drashland / rhum

A test double library
https://drash.land/rhum
MIT License
92 stars 6 forks source link

beforeAll() executes after each test case #90

Closed MVEMCJSUNPE closed 4 years ago

MVEMCJSUNPE commented 4 years ago

Summary

Maybe I just don't understand the functionality of Rhum.beforeAll because I'm stupid, but it seems that the the function input into Rhum.beforeAll gets executed for every test case instead of just once before all testcases. If this really is how Rhum.beforeOnly, then I would like for this to be changed to having the function that is input into Rhum.beforeAll be executed once before all test cases, as this is the convention of most other Javascript/Typescript testing frameworks. beforeAll vs beforeEach

Steps To Reproduce The Bug

Consider the following typescript file:

// blah.ts
import { Rhum } from 'https://deno.land/x/rhum@v1.1.4/mod.ts';

Rhum.testPlan('foo', () => {
    Rhum.testSuite('bar', () => {
        let i = 0;
        Rhum.beforeAll(() => {
            console.log('In beforeAll, the value of i is ' + i);
            i++;
        });

        Rhum.testCase('inch', () => {
            Rhum.asserts.assertEquals(1, 1);
        });

        Rhum.testCase('time', () => {
            Rhum.asserts.assertEquals(1, 1);
        });

        Rhum.testCase('foot', () => {
            Rhum.asserts.assertEquals(1, 1);
        });

        Rhum.testCase('gem', () => {
            Rhum.asserts.assertEquals(1, 1);
        });
    });
});

Rhum.run();

If we run the command deno test --allow-env blah.ts, how many times does the function input into Rhum.beforeAll get executed?

blah

Expected Behavior

I would like the function input into Rhum.beforeAll to be executed ONE time before all test cases, not once for every test case.

crookse commented 4 years ago

looking into this right now. seems like a bug, but we have tests that ensure the value of whatever is in beforeAll doesn't change. however it could be that our tests are incorrectly reporting.

crookse commented 4 years ago

confirmed. this is a bug.