samedi 24 juin 2017

SyntaxError: Unexpected token ( for jest

After setting up some postcss and webpack, some of my jest tests failed. All failed for the same error. Very strange error, it seems that Jest can't even recognize arrow function rather than async/await.

FAIL  tests/backend/integration/models/threadsModel.test.js
  ● Test suite failed to run

    /Users/albertgao/codes/node/projectTalk/tests/backend/integration/models/threadsModel.test.js:115
        test('Should return empty list when no data could be fetched', async () => {
                                                                             ^
    SyntaxError: Unexpected token (

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
      at handle (node_modules/worker-farm/lib/child/index.js:41:8)
      at process.<anonymous> (node_modules/worker-farm/lib/child/index.js:47:3)
      at emitTwo (events.js:106:13)

The test is simple and passed before:

test('Should return empty list when no data could be fetched', async () => {
    const result = await ThreadModel.getThreads(threads[19], 5);
    expect(result).toHaveLength(0);
});

I tried:

  • --no-cache
  • delete node_modules and re-install all modules

Still got this error.

I use the latest Jest

Any solution?

Aucun commentaire:

Enregistrer un commentaire