Skip to content

Commit

Permalink
fix(driver): Assertion on getCookie() is called twice (#8276)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomastomaslol authored Sep 14, 2020
1 parent 1244dd1 commit 5d6c89c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
12 changes: 12 additions & 0 deletions packages/driver/cypress/integration/commands/cookies_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,16 @@ describe('src/cy/commands/cookies', () => {

describe('.log', () => {
beforeEach(function () {
this.asserts = []

cy.on('log:added', (attrs, log) => {
if (attrs.name === 'getCookie') {
this.lastLog = log
}

if (attrs.name === 'assert') {
this.asserts.push(log)
}
})

Cypress.automation
Expand All @@ -381,6 +387,12 @@ describe('src/cy/commands/cookies', () => {
})
})

it('only logs assertion once when should is invoked', () => {
cy.getCookie('foo').should('exist').then(function () {
expect(this.asserts.length).to.eq(1)
})
})

it('ends immediately', () => {
cy.getCookie('foo').then(function () {
const { lastLog } = this
Expand Down
14 changes: 5 additions & 9 deletions packages/driver/src/cy/commands/asserting.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,11 @@ module.exports = function (Commands, Cypress, cy, state) {
throwAndLogErr(err)
}

let isCheckingExistence

// are we doing a length assertion?
if (reHaveLength.test(chainers) || reExistence.test(chainers)) {
isCheckingExistence = true
}
const isCheckingExistence = reExistence.test(chainers)
const isCheckingLengthOrExistence = isCheckingExistence || reHaveLength.test(chainers)

const applyChainer = function (memo, value) {
if (value === lastChainer) {
if (value === lastChainer && !isCheckingExistence) {
if (_.isFunction(memo[value])) {
try {
return memo[value].apply(memo, args)
Expand Down Expand Up @@ -99,7 +95,7 @@ module.exports = function (Commands, Cypress, cy, state) {
// because its possible we're asserting about an
// element which has left the DOM and we always
// want to auto-fail on those
if (!isCheckingExistence && $dom.isElement(subject)) {
if (!isCheckingLengthOrExistence && $dom.isElement(subject)) {
cy.ensureAttached(subject, 'should')
}

Expand All @@ -112,7 +108,7 @@ module.exports = function (Commands, Cypress, cy, state) {

// https://github.com/cypress-io/cypress/issues/883
// A single chainer used that is not an actual assertion, like '.should('be', 'true')'
if (chainers.length < 2 && !_.isFunction(memo[value]) && !isCheckingExistence) {
if (chainers.length < 2 && !isCheckingExistence && !_.isFunction(memo[value])) {
err = $errUtils.cypressErrByPath('should.language_chainer', { args: { originalChainers } })
err.retry = false
throwAndLogErr(err)
Expand Down

4 comments on commit 5d6c89c

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5d6c89c Sep 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.2.0/linux-x64/circle-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.2.0/circle-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5d6c89c Sep 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.2.0/win32-ia32/appveyor-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.2.0/appveyor-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/5.2.0/win32-ia32/appveyor-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.2.0/appveyor-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.2.0/win32-ia32/appveyor-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.2.0/appveyor-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.2.0/win32-ia32/appveyor-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.zip npm install https://cdn.cypress.io/beta/npm/5.2.0/appveyor-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5d6c89c Sep 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.2.0/win32-x64/appveyor-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.2.0/appveyor-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/5.2.0/win32-x64/appveyor-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.2.0/appveyor-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.2.0/win32-x64/appveyor-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.2.0/appveyor-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.2.0/win32-x64/appveyor-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.zip npm install https://cdn.cypress.io/beta/npm/5.2.0/appveyor-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5d6c89c Sep 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.2.0/darwin-x64/circle-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.2.0/circle-develop-5d6c89c82d074052ea99ad60d768d5ca379014de/cypress.tgz

Please sign in to comment.