Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test suite failed to run. Your test suite must contain at least one test. #7623

Closed
chriskuech opened this issue Jan 14, 2019 · 6 comments
Closed
Labels

Comments

@chriskuech
Copy link

🐛 Bug Report

Jest cannot find unit tests in file when using supertest inside. Example from the Jest for web frameworks example.

To Reproduce

createServer returns Promise<Express>, an express app.

This snippet currently passes when running jest

import request from "supertest";
import assert from "assert";
import { createServer } from "./server";

describe("/diag/json", async () => {
  it("should get sample json", async () => {
    assert.equal(1, 1);
  });
});

This snippet (almost identical to docs and blogs) fails because jest can't find any tests in the file.

import request from "supertest";
import { createServer } from "./server";

describe("/diag/json", async () => {
  const app = await createServer();
  it("should get sample json", async () => {
    const response = await request(app).get("/diag/json");
    expect(response.status).toBe(200);
  });
});

Error

  ● Test suite failed to run

    Your test suite must contain at least one test.

      at node_modules/jest-cli/build/TestScheduler.js:256:22

Expected behavior

Jest either passes running my unit tests or it fails from running my unit tests. (It currently fails from not running my unit tests)

Run npx envinfo --preset jest

  System:
    OS: Linux 4.18 Ubuntu 18.10 (Cosmic Cuttlefish)
    CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
  Binaries:
    Node: 10.14.1 - ~/.nvm/versions/node/v10.14.1/bin/node
    Yarn: 1.13.0 - ~/.nvm/versions/node/v10.14.1/bin/yarn
    npm: 6.5.0 - ~/.nvm/versions/node/v10.14.1/bin/npm
  npmPackages:
    jest: * => 23.6.0 
@jeysal
Copy link
Contributor

jeysal commented Jan 14, 2019

Tests must be defined synchronously, so you'll need to move createServer to a beforeEach or beforeAll, which may be async.

@jeysal
Copy link
Contributor

jeysal commented Feb 10, 2019

Took me a month, but I finally had some time to do something against these errors #7852 😄

@rubendmatos1985
Copy link

rubendmatos1985 commented Feb 4, 2020

A bit late but jest still fails with async and the documentation says very clear how to use async code. Either you have to remove this from the docs or you have to fix this issue.
Promises
If your code uses promises, there is a more straightforward way to handle asynchronous tests. Return a promise from your test, and Jest will wait for that promise to resolve. If the promise is rejected, the test will automatically fail.

For example, let's say that fetchData, instead of using a callback, returns a promise that is supposed to resolve to the string 'peanut butter'. We could test it with: `

I am doing my tests with promises and i am receiving the same error.

@SimenB
Copy link
Member

SimenB commented Feb 4, 2020

describe is not a test, it's just a grouping. You can use async in test and it, but the test function itself must be defines synchronously.

https://jestjs.io/docs/en/troubleshooting#defining-tests

@rubendmatos1985
Copy link

Ohh ok I understand. Thanks a lot

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants