jest-codemods icon indicating copy to clipboard operation
jest-codemods copied to clipboard

TypeError: Cannot read property 'object' of undefined

Open Justkant opened this issue 6 years ago • 2 comments

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.

Justkant avatar May 11 '18 15:05 Justkant

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.

skovhus avatar May 14 '18 19:05 skovhus

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 });
      });
    });
  });

Justkant avatar May 17 '18 14:05 Justkant