-
-
Notifications
You must be signed in to change notification settings - Fork 697
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
Add assertions for ES6 Maps and Sets #632
Comments
We already have a var len = keys.length,
any = flag(this, 'any'),
all = flag(this, 'all'),
actual,
expected;
if (_.type(obj) === 'map') {
actual = Array.from(obj.keys());
expected = keys;
} else {
actual = Object.keys(obj);
expected = keys.map(String);
} A good PR would also include some test coverage, and extend the existing documentation (found in the comments above the method). |
Hi everyone, TL;DR var myMap = new Map().set({}, 'value').set({lol: 'lel'}, 'laugh');
expect(myMap).to.have.all.keys({}, {lol: 'lel'}); Edit: Well, I've found a way to accept any object as a key in the case of Maps and Sets and still check for valid arguments when working with any other thing, I think if we're going to allow Maps and Sets to be use with this assertion we need to have full support for them. |
@lucasfcosta awesome! Look forward to the PR 😄. If it is a breaking change, make it against |
I would expect this to fail. Keys in maps and values in sets are by reference and checked that way using var k1 = {}, k2={}, myMap = new Map().set(k1,1)
myMap.should.have.key(k1) // myMap.has(k1).should.be.true
myMap.should.not.have.key(k2) // myMap.has(k2).should.be.false |
I'm not a fan of how keys() insist on an exact match instead of a subset match, but includes.keys() can match on subsets. As implemented, .all. seems to be superfluous. It implies that some other check happens but unless I'm missing something to.have.all.keys() and to.have.keys() perform the exact same match operation, whereas I would expect the former to be more strict. I'm commenting here only partially to register a complaint, and more so the next person doing a google search figures out why their tests are red. This may be a documentation complaint though. All of the examples assume that an exact match is desired. The countercase is never explored. |
@keithamus:
It would be cool if there would be assertions for ES6 Maps (and Sets).
For example something like:
Currently one could use:
But that doesn't work great..
The text was updated successfully, but these errors were encountered: