diff --git a/packages/driver/cypress/e2e/commands/misc.cy.js b/packages/driver/cypress/e2e/commands/misc.cy.js index 4238afd8e1bf..ed8ce643d2b0 100644 --- a/packages/driver/cypress/e2e/commands/misc.cy.js +++ b/packages/driver/cypress/e2e/commands/misc.cy.js @@ -10,6 +10,11 @@ describe('src/cy/commands/misc', () => { it('nulls out the subject', () => { cy.noop({}).end().then((subject) => { expect(subject).to.be.null + + // We want cy.end() to break the subject chain - any previous entries + // (in this case `{}`) should be discarded. No re-running any previous + // query functions once you've used `.end()` on a chain. + expect(cy.subjectChain()).to.eql([null]) }) }) }) diff --git a/packages/driver/src/cy/commands/misc.ts b/packages/driver/src/cy/commands/misc.ts index b4efd916742e..4594ee325224 100644 --- a/packages/driver/src/cy/commands/misc.ts +++ b/packages/driver/src/cy/commands/misc.ts @@ -11,7 +11,8 @@ interface InternalWrapOptions extends Partial { - Commands.addQuery('end', () => () => null) + Commands.add('end', () => null) + Commands.add('noop', (arg) => arg) Commands.addQuery('log', (msg, ...args) => { Cypress.log({ @@ -24,8 +25,6 @@ export default (Commands, Cypress, cy, state) => { return () => null }) - Commands.add('noop', (arg) => arg) - Commands.addAll({ wrap (arg, userOptions: Partial = {}) { const options: InternalWrapOptions = _.defaults({}, userOptions, {