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

describe should throw if passed a function that returns a promise #5034

Open
lucacasonato opened this issue Jun 12, 2024 · 2 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@lucacasonato
Copy link
Member

describe is used to group related tests. Actual test code should be put in an it block or a before*/after* hook. For example, you can initialize node in a beforeAll hook:

import { beforeAll, describe, it } from "jsr:@std/testing@^0.220.1/bdd";
import { assertEquals } from "jsr:@std/assert@^0.220.1/assert_equals";

describe("DOMNode", () => {
  let node;

  beforeAll(async () => {
    node = await xmlFromString();
  });

  it("in root namespace", () => assertEquals());
  it("in leaf namespace", () => assertEquals());
});
Deno.test equivalent
import { assertEquals } from "jsr:@std/assert@^0.220.1/assert_equals";

Deno.test("DOMNode", async (t) => {
  let node = await xmlFromString();

  await t.step("in root namespace", () => assertEquals());
  await t.step("in leaf namespace", () => assertEquals());
});

The error message could definitely be improved. Jest throws a helpful error if the callback passed to describe returns a promise or anything other than undefined.

Originally posted by @0f-0b in denoland/deno#22991 (comment)

@lucacasonato lucacasonato changed the title describe is used to group related tests. Actual test code should be put in an it block or a before*/after* hook. For example, you can initialize node in a beforeAll hook: describe should throw if passed a function that returns a promise Jun 12, 2024
@kt3k
Copy link
Member

kt3k commented Jun 12, 2024

Hey @KyleJune, can you take a look at this?

@KyleJune
Copy link
Contributor

Hey @KyleJune, can you take a look at this?

All the call signatures already only accept callbacks that return void. I believe the issue would have been caught if they were using TypeScript but I think it would be fine to add a check to the code so that JavaScript users will get an error if they try having it return anything.

@kt3k kt3k added the bug Something isn't working label Jun 26, 2024
@iuioiua iuioiua self-assigned this Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants