Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't chain mutliple `cy.should(callbackFn)` #4981

Closed
garretmh opened this issue Aug 13, 2019 · 5 comments · Fixed by #6128
Closed

Can't chain mutliple `cy.should(callbackFn)` #4981

garretmh opened this issue Aug 13, 2019 · 5 comments · Fixed by #6128

Comments

@garretmh
Copy link

@garretmh garretmh commented Aug 13, 2019

Current behavior:

Chaining multiple .should() commands that use callback functions throws if any of the callback functions other than the last one contain more than one assertion.

cy.wrap('ab')
  .should(subject => {
    expect(subject).to.be.a('string');
    expect(subject).to.contain('a');
  })
  .should(subject => {
    expect(subject).to.contain('b');
  });

Screenshot from 2019-08-13 16-01-21

Desired behavior:

Chaining multiple .should() commands should work regardless of the number of assertions per callback function.

Steps to reproduce: (app code and test code)

describe('chaining cy.should(callbackFn)', () => {
  it('should work, but does not', () => {
    cy.wrap('a')
      .should(subject => {
        expect(subject).to.be.a('string');
        expect(subject).to.contain('a');
      })
      .should(() => {});
  });

  it('works when separated by .then()', () => {
    cy.wrap('a')
      .should(subject => {
        expect(subject).to.be.a('string');
        expect(subject).to.contain('a');
      })
      // Adding an empty then fixes the issue.
      .then(() => {})
      .should(() => {});
  });

  it('works when there is only one assertion per callbackFn', () => {
    cy.wrap('a')
      .should(subject => {
        expect(subject).to.be.a('string');
      })
      .should(subject => {
        expect(subject).to.contain('a');
      })
      .should(() => {});
  });
});

Versions

Cypress: 3.4.5
OS: Ubuntu 19.04
Browser: Electron 61

@mpahuja

This comment has been minimized.

Copy link

@mpahuja mpahuja commented Aug 30, 2019

these are two different assertion libraries. Whats the motivation behind trying to use both at the same time?

@jennifer-shehane

This comment has been minimized.

Copy link
Member

@jennifer-shehane jennifer-shehane commented Dec 17, 2019

Simpler example from #5979

it('two should callbacks (crashes and burns)', () => {
  cy.wrap(null)
    .should(() => {
      console.log('in should()')
      expect(true).to.be.true
      expect(true).to.be.true
    })
    .and(() => {
      console.log('in and ()')
    })
})
@bahmutov

This comment has been minimized.

Copy link
Contributor

@bahmutov bahmutov commented Dec 17, 2019

Relevant stack
Screen Shot 2019-12-16 at 9 30 38 PM

@cypress-bot

This comment has been minimized.

Copy link

@cypress-bot cypress-bot bot commented Jan 10, 2020

The code for this is done in cypress-io/cypress#6128, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot

This comment has been minimized.

Copy link

@cypress-bot cypress-bot bot commented Jan 10, 2020

Released in 3.8.2.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v3.8.2, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants
You can’t perform that action at this time.