I am encountering a behaviour that I can't explain. Depending on using import or require, this test successes (import) or fails (require).
In case of fail, I have the following error :
PhantomJS 2.1.1 (Windows 7 0.0.0) immutability a number is immutable FAILED undefined is not a constructor (evaluating 'expect((0, _immutable.List)([1])).toEqualImmutable((0, _immutable.List)([1]))')
Here is the code :
import { Map, List } from 'immutable';
const expect = require("expect");
// import expectImmutable from "expect-immutable";
const expectImmutable = require("expect-immutable");
expect.extend(expectImmutable);
describe("immutability", () => {
describe("a number", () => {
function increment(currentState) {
return currentState + 1;
}
it("is immutable", () => {
expect(List([1])).toEqualImmutable(List([1]));
expect(Map({ a: 1 })).toEqualImmutable(Map({ a: 1 }));
let state = 42;
let nextState = increment(state);
expect(List([nextState])).toEqualImmutable(List([43]));
expect(List([state])).toEqualImmutable(List([42]));
});
});
});
Does anyone have an explanation of what is happening behind the scene ? Thanks a lot for your attention.
Aucun commentaire:
Enregistrer un commentaire