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

Before and After hooks of other test get called even when skipped #52

Open
ade885 opened this issue Mar 19, 2024 · 0 comments
Open

Before and After hooks of other test get called even when skipped #52

ade885 opened this issue Mar 19, 2024 · 0 comments

Comments

@ade885
Copy link

ade885 commented Mar 19, 2024

before, beforeEach, afterEach and after hooks of other tests in a file gets called whenever a singular test is intended to be run.

See example

When you run
node --test --test-name-pattern "should add two numbers " on this test file, it is not meant to call the before hooks of the
second and third describe in the code below.

see the codesanbox here

const assert = require('node:assert');
const { before, beforeEach, it, describe, after } = require("node:test");

describe("First test", () => {
  describe("first describe", () => {
    before(() => {
      console.log("in first before ");
    });

    it("should add two numbers ", () => {
      assert.equal(1 + 1, 2);
    });
  });

  describe("second describe", () => {
    before(() => {
      console.log("in second before ");
    });

    it("should multiply two numbers", () => {
      assert.equal(1 *1, 1);
    });
  });

  describe("third describe", () => {
    before(() => {
      console.log("in third before ");
    });

    it("should divide two numbers ", () => {
      assert.equal(6/3, 2);
    });
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant