Inspect doesn't work properly for Maps and Sets - It displays an empty object
See original GitHub issueAs I was implementing the .deep
flag support on the keys
assertion I noticed that utils.inspect
isn’t working properly when it comes to Maps and Sets. Instead of returning the values inside the Map or Set it returns the following string: {}
.
You can reproduce this behavior by doing, for example:
chai.use(function (_chai, utils) {
var inspectSet = _utilsinspect(new Set([{iAmAn: 'item'}, {thisIs: 'anotherItem'}]));
var inspectMap = utils.inspect(new Map([[{iAmA: 'key'}, 'aValue']]))
console.log(inspectSet); // --> {}
console.log(inspectMap); // --> {}
});
What do you guys think should be the desired output when inspecting maps or sets?
IMO the ideal output would be:
chai.use(function (_chai, utils) {
var inspectSet = _utilsinspect(new Set([{iAmAn: 'item' }, {thisIs: 'anotherItem'}]));
var inspectMap = utils.inspect(new Map([[{iAmA: 'key' }, 'aValue']]))
console.log(inspectSet); // Desired --> [ {iAmAn: 'item' }, { thisIs: 'anotherItem' } ]
console.log(inspectMap); // Desired --> [ [ { iAmA: 'key' }, 'aValue' ] ]
});
I think this wouldn’t be a difficult fix. Maybe adding a check alongside these other checks and then calling a function to iterate through every entry and format the Map/Set members should be enough. This will be very similiar to what we already do in formatArray
.
I will make sure to submit a PR for this before implementing the deep
flag for Maps/Sets because this will be very useful to create good test cases.
Please let me know if you’ve got any idea or opinion about this 😉
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:14 (10 by maintainers)
Top GitHub Comments
This got accidentally closed because #668’s description contained the text
we need to fix #662 in order to enable all tests
. Reopening.I’ve got some other bits I want to work on for chaijs/loupe so hold off on this one just for now. We’ll get this fixed for 4.0 though 😄