m-radzikowski / aws-sdk-client-mock

AWS JavaScript SDK v3 mocks for easy unit testing. 🖋️ Typed 🔬 Tested 📄 Documented 🛠️ Maintained
https://m-radzikowski.github.io/aws-sdk-client-mock/
MIT License
811 stars 40 forks source link

Jest matcher expect().toEqual() throws error "TypeError: this.customTesters is not iterable" #219

Closed gborobio73 closed 5 months ago

gborobio73 commented 7 months ago

Checklist

Bug description

Thanks a lot for this library 🙏

Jest matcher expect().toEqual() throws an error "TypeError: this.customTesters is not iterable". I'm not sure if this is the intended behavior.

Reproduction

// test.spec.ts
import 'aws-sdk-client-mock-jest';

it('test', () => {
  expect({ a: 'a' }).toEqual({ a: 'a' });
});

Running this test results in:

✕ test (5 ms)

  ● test

    TypeError: this.customTesters is not iterable

      2 |
      3 | it('test', () => {
    > 4 |   expect({ a: 'a' }).toEqual({ a: 'a' });
        |                      ^
      5 | });
      6 |

If I remove the import everything works as expected.

Thanks a lot!

Environment

alexander-cox commented 6 months ago

I had an almost identical issue to this but I found that if I bumped the versions of jest and ts-jest to versions ^v29 it resolved itself

gborobio73 commented 6 months ago

I had an almost identical issue to this but I found that if I bumped the versions of jest and ts-jest to versions ^v29 it resolved itself

Oh, thanks! I'll try that 🙏

Kairn commented 6 months ago

In my project, I tried to replicate the same matchers file (packages/aws-sdk-client-mock-jest/src/jestMatchers.ts), and the same issue occurs.

However, I changed import {expect} from 'expect' (this line: https://github.com/m-radzikowski/aws-sdk-client-mock/blob/main/packages/aws-sdk-client-mock-jest/src/jestMatchers.ts#L7) to import {expect} from '@jest/globals', and it suddenly started to work without upgrading the library.

Not sure why, but this was the import used in the Jest documentation too (https://jestjs.io/docs/expect#expectextendmatchers). Maybe consider making this change as a fix.

m-radzikowski commented 5 months ago

Using @jest/globals types works with Jest 29.

Using @types/jest works with both Jest 28 and 29.

See more on Jest types: https://jestjs.io/docs/getting-started#using-typescript

If there is still a problem using this setup, please reopen providing reproduction example and exact package versions.