EmandM/ts-mock-imports

Timeout Error With Multiple Tests In One File

JimLynchCodes opened this issue · 3 comments

Hi!

Thanks for this great project. Mocking things with sinon in typescript has always been somewhat difficult for me, and I really like the api of this library!

The thing is though, I am getting this error when I run the tests in this file:

(node:91020) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
  ok
undefined
;foobarrr
    1) ok

  deleteBook sucessfull call
deleted! 46
    ✓ returns 200 containing the data that Book.deleteBook resolves.

  deleteBook errors
err is Error: Oh no, there was an error!
    ✓ returns 400 with errors array containing Book.deleteBook error


  2 passing (2s)
  1 failing

  1) ok
       ok:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/jim/Git-Projects/CRUD-Lambda-TypeScript-Mongo/src/create.test.ts)
      at listOnTimeout (internal/timers.js:531:17)
      at processTimers (internal/timers.js:475:7)



npm ERR! Test failed.  See above for more details.

It's strange because if I run either of them with an "it.only" then each of them pass individually!

Do I need to add some extra cleanup code in order to mock a thing multiple times within a file?

Thanks! 🙏

bump 🙃

Sounds like your tests are running in under 2 seconds per test, but when you run the whole test suite it runs for longer than 2 seconds and triggers the Mocha timeout. There's a setting that lets you configure the timeout limit, I'd suggest adjusting that and seeing if the issue resolves.

Closing this issue as the problem looks to be with Mocha and not with this library.

@EmandM can you elaborate on this?

Both tests are finishing in under 2 seconds, especially with the async being mocked, so I don't see how this setting could be causing the issue. 🤔

I don't really mind, but just fyi in general it is not very nice to close someone else's ticket without confirming that the issue has been resolved. ❤️