Jest TypeError: Cannot read property 'useFakeTimers' of undefined

Describe the issue/error/question

run a unit test under packages/nodes-base got failed.
But I can fix it by remove node_models and reinstall again with npm install

Steps to reproduce?

  1. clone n8n repo
  2. lerna bootstrap --hoist
  3. npm run build
  4. add the code below under packages/nodes-base/test/nodes/Stripe/helpers.test.js
beforeAll(() => {
		.setSystemTime(new Date('2021-02-18 12:24:00'));


What is the error message (if any)?

TypeError: Cannot read property ‘useFakeTimers’ of undefined

Share the output returned by the test

PASS test/nodes/Postgres/Postgres.node.functions.test.js
FAIL test/nodes/Stripe/helpers.test.js
  ● adjustMetadata › it should adjust multiple metadata values

    TypeError: Cannot read property 'useFakeTimers' of undefined

      3 | beforeAll(() => {
      4 | 	jest
    > 5 | 		.useFakeTimers('modern')
        | 		 ^
      6 | 		.setSystemTime(new Date('2021-02-18 12:24:00'));
      7 |
      8 | });

      at Object.useFakeTimers (../../node_modules/jest/node_modules/jest-runtime/build/index.js:1751:38)
      at Object.<anonymous> (test/nodes/Stripe/helpers.test.js:5:4)

PASS test/placeholder.test.ts

Information on your n8n setup

  • Running n8n via [Docker, npm,, desktop app]: npm

Thanks for your report.

For reference, the issue seems to be mismatched versions of @jest/fake-timers.

Cannot look more deeply into this at the moment. Could you install try installing @jest/fake-timers in packages/nodes-base and switch back to the legacy implementation in the meantime?

1 Like