How to fix "Test suite failed to run" when running a test with jest

innis

I'm learning how to write tests with jest and I'm getting this huge log exit when I run them.

Since it's a tiny code, I see no problem in posting it entirely.

describe('First test', async () => {
  const OLD_ENV = process.env;

  beforeEach(() => {
    jest.resetModules();
    process.env = { MONGO_CLUSTER_URI: <<<hidden for security reasons>>>' };
  })

  afterEach(() => {
    process.env = OLD_ENV;
  })

  test('Should pass', async () => {
    console.log('Testing...');
    const response = await index.handler({ event: 'input' }, { });
    console.log(response);
    expect(response).toBe(true);
  })
})

I don't know if it's supposed get me such a big output, but i think it's not since it looks like it's throwing some kind of error. I'm posting the output below so you guys can help me.

[email protected]:~/lambda-testes-jest/functions/cf_post_processing$ lerna run test --scope cf_post_processing
info cli using local version of lerna
lerna notice cli v3.16.4
lerna info versioning independent
lerna info filter [ 'cf_post_processing' ]
lerna info Executing command in 1 package: "npm run test"
lerna ERR! npm run test exited 1 in 'cf_post_processing'
lerna ERR! npm run test stdout:

> [email protected] test /home/tvrsky/lambda-testes-jest/functions/cf_post_processing
> jest *.test.js

  console.log node_modules/jest-jasmine2/build/jasmine/Env.js:502
      ● Test suite failed to run

        Returning a Promise from "describe" is not supported. Tests must be defined synchronously.
        Returning a value from "describe" will fail the test in a future version of Jest.

          1 | const index = require('./index');
          2 | 
        > 3 | describe('First test', async () => {
            | ^
          4 |   const OLD_ENV = process.env;
          5 | 
          6 |   beforeEach(() => {

          at addSpecsToSuite (node_modules/jest-jasmine2/build/jasmine/Env.js:504:17)
          at Object.describe (index.test.js:3:1)


  console.log index.test.js:16
    Testing...

  console.log index.js:22
    undefined

  console.log index.test.js:18
    { statusCode: 500,
      body: { message: 'db.collection is not a function' } }


lerna ERR! npm run test stderr:
FAIL ./index.test.js (9.7s)
  First test
    ✕ Should pass (137ms)

  ● First test › Should pass

    expect(received).toBe(expected) // Object.is equality

    Expected: true
    Received: {"body": {"message": "db.collection is not a function"}, "statusCode": 500}

      17 |     const response = await index.handler({ event: 'input' }, { });
      18 |     console.log(response);
    > 19 |     expect(response).toBe(true);
         |                      ^
      20 |   })
      21 | })
      22 | 

      at Object.toBe (index.test.js:19:22)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        16.901s
Ran all test suites matching /index.test.js/i.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `jest *.test.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/tvrsky/.npm/_logs/2019-09-18T18_27_53_742Z-debug.log

lerna ERR! npm run test exited 1 in 'cf_post_processing'
Mitch Lillie

The first line of your test should be

describe('First test', () => {

The error is telling you what the issue is. Basically, describe shouldn't be asynchronous, because multiple describes or tests within them will run concurrently.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive