jest-codemods
jest-codemods copied to clipboard
TypeError: Cannot read property 'object' of undefined
I just encountered the error on this line I think: https://github.com/skovhus/jest-codemods/blob/9c9a183c9e996b13c0f4e1be39c1e025c256a89d/src/transformers/expect.js#L70
This code was the problem:
expect(u)
.toContainKeys(['id', 'name', 'pic'])
.toNotContainKeys(['mail', 'token']);
But those 2 work:
expect(u)
.toContainKeys(['id', 'name', 'pic']);
or
expect(u)
.toNotContainKeys(['mail', 'token']);
It's trivial for me to fix on my codebase but I thought it could be useful for anyone getting the same error on a larger codebase.
Thanks for reporting this!
Let me know if you would like to look at submitting a PR to either demonstrate the error with a failing test case or if you want to try to fix the transformer.
Hi,
In the same way but I don't know if it's related because no errors.
describe('get', () => {
it('should return the host status', function() {
return this.client.send('host:get').then(res =>
expect(res)
.toContainKeys(['active', 'hostSocketId'])
.toContain({ active: false }),
);
});
});
Get transform to:
describe('get', () => {});
But this version:
describe('get', () => {
it('should return the host status', function() {
return this.client.send('host:get').then(res => {
expect(res).toContainKeys(['active', 'hostSocketId']);
expect(res).toContain({ active: false });
});
});
});
Get transform correctly:
describe('get', () => {
it('should return the host status', function() {
return this.client.send('host:get').then(res => {
['active', 'hostSocketId'].forEach(e => {
expect(Object.keys(res)).toContain(e);
});
expect(res).toContain({ active: false });
});
});
});