2

Issue

The test below should fail, but it is passing:

it('should fail', () => {
  const actual = new Set('a');
  const expected = new Set('b');
  expect(actual).toEqual(expected);
});

enter image description here

Background & Question

I'm using the expect package from npm. I'm using Babel 5 to use Set. I'm using Node 5, so the Set being used should be native. Am I doing something wrong, or does this look like a bug in the expect package in the way it handles Sets? I've cross posted an issue on the package as I'm not sure.

  • You could try hapijs [code](https://github.com/hapijs/code) instead of expect for assertions, I just tested the assertion and it worked – simon-p-r Nov 23 '15 at 22:39
  • See this question http://stackoverflow.com/questions/31128855/comparing-ecma6-sets-for-equality – frkk Nov 23 '15 at 22:44

1 Answers1

2

1. This is "expected behavior"

expect depends on deep-equal, which does not support sets and maps.

This in consistent with the behavior of node's assert :

var a = new Set('a');
var b = new Set('b');
console.log(require('assert').deepEqual(a, b) || 'ok');
// Prints 'ok' !

This issue has been discussed here :

assert: add support for Set and Map

This comment is particularly interesting :

I don't think we should do this (or anything else in #2309). Assert should remain used only for testing io.js itself, and not try to be a good general assertion library. If io.js tests need this ability enough times that we need to factor it out, we should, but until then, just adding it because it'd be nice isn't a good idea IMO.

2. Workaround

You can either:

Community
  • 1
  • 1
KeatsPeeks
  • 19,126
  • 5
  • 52
  • 83