question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add assertions for ES6 Maps and Sets

See original GitHub issue

@keithamus:

@tiemevanveen you should raise a new issue - we can discuss the design of this and work towards adding it as a feature 😄


It would be cool if there would be assertions for ES6 Maps (and Sets).

For example something like:

expect(myMap).to.have.key('some_key');

Currently one could use:

expect(myMap.has('some_key'), 'map should have some_key').to.be.true;

But that doesn’t work great…

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bnord01commented, Mar 22, 2016

@lucasfcosta

Should this, for example, be allowed?

var myMap = new Map().set({}, 'value').set({lol: 'lel'}, 'laugh');
expect(myMap).to.have.all.keys({}, {lol: 'lel'});

I would expect this to fail. Keys in maps and values in sets are by reference and checked that way using has

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
0reactions
lucasfcostacommented, Mar 22, 2016

@bnord01 thanks for the explanation, I didn’t know that. Makes total sense to me. 😃

EDIT Note: This is done that way on #633

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing Maps/Sets with QUnit (or other Unit Testing Tool)
The intention is to assert that the elements of the Sets/Maps are equal. Both the both assertions should fail. Is there an equivalent...
Read more >
19. Maps and Sets - Exploring JS
19.2.4 Iterating over Maps # ... Let's set up a Map to demonstrate how one can iterate over it. const map = new...
Read more >
JavaScript maps vs. sets: Choosing your data structure
Every Set object will originally have a has() method that can be called to assert whether or not an element with a specified...
Read more >
Collecting and iterating, the ES6 way - Chrome Developers
Set s offer a way of keeping track of a collection of items in which each item can appear at most once. Map...
Read more >
How JavaScript works: understanding Maps and their use ...
Maps were introduced in JavaScript in ES6 . ... In Maps, you can add a new set of entries (key-value pair) at any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found