Jest: How to ignore __mocks__ folder for specific test and instead use a mock I define in the test file?

I have a __mocks__ folder that mocks out a node module. This works for most of my tests, but in one particular test I need a custom mock. I need my unit-tested code to ignore the mock in the __mocks__ folder, and use a specific mock that I define in the test file.

I tried using jest.unmock(), however this prevents me from defining specific mocks in my unit test (thing.test.js). If I then add some mocks or modify the module I'm mocking, the changes don't get added to the code I'm testing (thing.js).

Example:

  • thing.js imports AWS.js module
  • __mocks__/AWS.js contains AWS.js module mock
  • other tests use __mocks__/AWS.js
  • thing.test.js wants to create a custom mock that doesn't get overwritten by __mocks__/AWS.js and doesn't affect other tests -> how to do this??