user3773571
user3773571

Reputation:

Expect tests don't work with the ES6 / ES2015 Set object

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.

Upvotes: 2

Views: 469

Answers (1)

KeatsPeeks
KeatsPeeks

Reputation: 19337

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:

Upvotes: 2

Related Questions