On this page

    M

    beforeEach

    History
    beforeEach(fn?, options?): void
    Attributes
    The hook function. If the hook uses callbacks, the callback function is passed as the second argument. Default: A no-op function.
    options:Object
    Configuration options for the hook. The following properties are supported:
    Allows aborting an in-progress hook.
    timeout?:number
    A number of milliseconds the hook will fail after. If unspecified, subtests inherit this value from their parent. Default: Infinity.

    This function creates a hook that runs before each test in the current suite.

    describe('tests', async () => {
      beforeEach(() => console.log('about to run a test'));
      it('is a subtest', () => {
        // Some relevant assertion here
      });
    });