3 ms·
Why does your unit test need to wait one second? Or are you controlling the system time, but it still had that error?
by steve_adams_86 2y ago
Why does your unit test need to wait one second? Or are you controlling the system time, but it still had that error?
- bufferoverflow 2y agoHow else would you test if something happens after 1 second or not?
- steve_adams_86 2y agoBy mocking the system time and manually progressing it a set amount of time. Otherwise your tests actually take seconds rather than a few milliseconds. Not a great example, but here is something I did recently that tests time based state (thousands of seconds) but the suite passes in tens of milliseconds. It also uses a random number generator with a deterministic mode to allow random behaviour in production, but deterministic results in tests (unrelated but also handy) https://github.com/steveadams/minesweeper-store/blob/main/src/store/store.test.ts https://github.com/steveadams/minesweeper-store/blob/main/sr... Some writing about the repo in case you’re curious: https://steve-adams.me/building-minesweeper-with-xstate-store/ https://steve-adams.me/building-minesweeper-with-xstate-stor...