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

expect(map).to.be.empty does not behave naturally #6072

Closed
janakdr opened this issue Dec 31, 2019 · 2 comments
Closed

expect(map).to.be.empty does not behave naturally #6072

janakdr opened this issue Dec 31, 2019 · 2 comments

Comments

@janakdr
Copy link

janakdr commented Dec 31, 2019

it('expect map', () => {
    expect(new Map([['a', 1]])).to.not.be.empty;
});

This test fails with the incorrect assertion: "expected {} not to be empty". It seems like Cypress is interpreting the Map object as some kind of DOM element, which it thinks is empty? Similarly, this test incorrectly passes if the .not is removed.

Screen Shot 2019-12-31 at 1 48 00 PM

Cypress doesn't explicitly say what it does for the .empty predicate in its assertions documentation but it does link to the full list of assertions which specify that for a Map, it will assert that the map has size 0. Even if the test code is changed to expect(new Map([['a', 1]])).to.be.a('map').that.is.not.empty the "empty" assertion is the one that fails.

@jennifer-shehane
Copy link
Member

This comes directly from Chai assertions and was not supported until Chai 4.0 as noted here: chaijs/chai#781

Support for asserting empty against Map will come in Cypress v4.0 which includes an update of Chai to 4.2.0 and other breaking changes. #4270

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

@flotwig
Copy link
Contributor

flotwig commented Feb 6, 2020

Released in 4.0.0.

@cypress-io cypress-io locked as resolved and limited conversation to collaborators Mar 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants