`originalPositionFor` returns object with hidden properties
Mingun opened this issue · 1 comments
Mingun commented
I try to write a test for my source map generator and faced with a problem.
I use Jest as a testing library and a chai
as a matcher:
it("my test", () => {
const generated = { line: ..., column: ... };
const original = { line: ..., column: ..., source: ..., name: ... };
const map = ...;
return SourceMapConsumer.fromSourceMap(map).then(consumer => {
chai.expect(consumer.originalPositionFor(generated)).to.be.equal(original);
});
}
This test fails with a message:
● Peggy API › generate › generates source map › global initializer
assert.deepStrictEqual(received, expected)
Expected value to deeply and strictly equal to:
{"column": 10, "line": 2, "name": "$top_level_initializer", "source": "-"}
Received:
{"column": 10, "line": 2, "name": "$top_level_initializer", "source": "-"}
Message:
expected { Object (source, line, ...) } to equal { Object (line, column, ...) }
Difference:
Compared values have no visual difference.
240 |
241 | return SourceMapConsumer.fromSourceMap(map).then(consumer => {
> 242 | expect(consumer.originalPositionFor(generated)).to.be.equal(original);
| ^
243 | });
244 | }
245 |
at test/api/pegjs-api.spec.js:242:65
The jestjs/jest#5998 explains that this can happened because of additional properties in the one object. I'm absolutely sure that original
is just a POD JSON object, so the problem in the originalPositionFor
result. This creates difficults in testing
Mingun commented
Nevermind. It's my fault. Chai's equal
performs strict assertions. The correct assertion in my case would be with deep
:
chai.expect(consumer.originalPositionFor(generated)).to.be.deep.equal(original);