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

BeforeEach & AfterEach hooks should behave the same as in jest #13

Open
biohazard999 opened this issue Jul 3, 2020 · 0 comments
Open
Labels
enhancement New feature or request good first issue Good for newcomers
Projects

Comments

@biohazard999
Copy link
Contributor

biohazard999 commented Jul 3, 2020

In jest the execution is like the following:

Order of execution of describe and test blocks
Jest executes all describe handlers in a test file before it executes any of the actual tests. This is another reason to do setup and teardown inside before* and after* handlers rather than inside the describe blocks. Once the describe blocks are complete, by default Jest runs all the tests serially in the order they were encountered in the collection phase, waiting for each to finish and be tidied up before moving on.

Consider the following illustrative test file and output:

describe('outer', () => {
  console.log('describe outer-a');

  describe('describe inner 1', () => {
    console.log('describe inner 1');
    test('test 1', () => {
      console.log('test for describe inner 1');
      expect(true).toEqual(true);
    });
  });

  console.log('describe outer-b');

  test('test 1', () => {
    console.log('test for describe outer');
    expect(true).toEqual(true);
  });

  describe('describe inner 2', () => {
    console.log('describe inner 2');
    test('test for describe inner 2', () => {
      console.log('test for describe inner 2');
      expect(false).toEqual(false);
    });
  });

  console.log('describe outer-c');
});

// describe outer-a
// describe inner 1
// describe outer-b
// describe inner 2
// describe outer-c
// test for describe inner 1
// test for describe outer
// test for describe inner 2

In Tasty this behaviour is currently different:

Describe("Scopes", () =>
            {
                BeforeEach(() => Console.WriteLine("Before Scope"));
                AfterEach(() => Console.WriteLine("After Scope"));

                Describe("Nested #1", () =>
                {
                    BeforeEach(() => Console.WriteLine("Before Nested #1"));
                    AfterEach(() => Console.WriteLine("After Nested #1"));

                    It("test #1", () => Console.WriteLine("test #1"));
                });

                Describe("Nested #2", () =>
                {
                    BeforeEach(() => Console.WriteLine("Before Nested #2"));
                    AfterEach(() => Console.WriteLine("After Nested #2"));

                    It("test #1", () => Console.WriteLine("test #2"));
                });
            });
Before Nested #1
test #1
After Nested #1
👍 [00:00:00.0077]  Scopes Nested #1 test #1
Before Nested #2
test #2
After Nested #2
👍 [00:00:00.0008]  Scopes Nested #2 test #1

=============================================================================================================================================================
Summary:              F0 |              I0 |             NR0 |              S2 | T2
Time:    [00:00:00.0000] | [00:00:00.0000] | [00:00:00.0000] | [00:00:00.0085] | [00:00:00.0085]
Outcome:         Success
=================================================================================================

which is plain wrong

@biohazard999 biohazard999 added this to To do in 0.1.0 via automation Jul 3, 2020
@biohazard999 biohazard999 removed this from To do in 0.1.0 Jul 6, 2020
@biohazard999 biohazard999 added this to To Do in 0.2.0 via automation Jul 6, 2020
@biohazard999 biohazard999 added enhancement New feature or request good first issue Good for newcomers labels Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
0.2.0
  
To Do
Development

No branches or pull requests

1 participant