Manually transferring https://github.com/facebook/react/issues/18758 to here. During debugging, it was determined to be a Jest issue.
@gaearon rightly agreed with me that the issue won't get fixed by sitting in the React repo. But they used their facebook admin powers to lock the issue, instead of using GitHub's "Transfer Issue" feature to get it here with all its detail in an instant. Ah, well.
People (including React repo maintainers, apparently) are seeing variations on TypeError: Cannot assign to read only property 'Symbol(...)' of object '[object ...]' when they do expect(...).toBe(...) and expect(...).toEqual(...).
The initial response is that it's not a very helpful error message.
Here's one clue that might explain it:
It happens when calling
replaceMatchedToAsymmetricMatcher()insideprintDiffOrStringify()https://github.com/facebook/jest/blob/master/packages/jest-matcher-utils/src/index.ts#L359
@SimenB any ideas?
_Originally posted by @pahan35 in https://github.com/facebook/react/issues/18758#issuecomment-636249433_
And a suggestion about what should be done about it:
We see a current message because
replaceMatchedToAsymmetricMatcherfails on preparing the diff.IMHO it's not about improving the error message, it's about fixing
replaceMatchedToAsymmetricMatcherto print the diff for DOM elements without failures.
_Originally posted by @pahan35 in https://github.com/facebook/react/issues/18758#issuecomment-647179531_
Hmm I didn鈥檛 even know there鈥檚 a way to transfer issues. 馃榾
@WeiAnAn ideas? It throws during assignment here: https://github.com/facebook/jest/blob/c9c8dba4dd8de34269bdb971173659399bcbfd55/packages/jest-matcher-utils/src/Replaceable.ts#L57
Sorry guys.
I'm trying to figure out the problem and solve it.
Found problem at https://github.com/facebook/jest/blob/c9c8dba4dd8de34269bdb971173659399bcbfd55/packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts#L58-L74
We need to set symbol key property descriptor.
But I got error on typescript that symbol type cannot be object key.
An index signature parameter type must be either 'string' or 'number'.
Will continue work tomorrow.
If anyone interested in, welcom to take it.
Found problem at
We need to set symbol key property descriptor.
But I got error on typescript that symbol type cannot be object key.
An index signature parameter type must be either 'string' or 'number'.Will continue work tomorrow.
If anyone interested in, welcom to take it.
https://github.com/microsoft/TypeScript/issues/1863 Probably related to the error
Here is the minimal to reproduce this error.
test('test', () => {
const a = {};
const b = {};
const symbolKey = Symbol.for('key');
Object.defineProperty(a, symbolKey, {
configurable: true,
enumerable: true,
value: {
a: 1,
},
writable: false,
});
Object.defineProperty(b, symbolKey, {
configurable: true,
enumerable: true,
value: {
a: 1,
},
writable: false,
});
expect(a).toBe(b);
});
@WeiAnAn we can do a // @ts-expect-error to suppress it - better than failing at runtime 馃檪
That's awesome, thanks a lot for the fix, @WeiAnAn and @SimenB! 馃槃
Most helpful comment
https://github.com/microsoft/TypeScript/issues/1863 Probably related to the error