Skip to content

beforeAll should ignore non-function values #2149

@silverwind

Description

@silverwind

Describe the bug

beforeAll accepts a optional teardown function returned from the callback, but there is a typecheck being performed which throws a TypeError: hook teardown value must be function, received "boolean" when truthy non-function values like true are returned. It is useful for one-liners like:

beforeAll(async () => await connectDatabase()); // if connectDatabase returns `true`, vitest throws

This typecheck breaks compatibilty with jest which does not typecheck the return value, so I suggest vitest to just silently ignore any non-function value returned in beforeAll.

Reproduction

Works in jest but throws in vitest:

beforeAll(() => true); // TypeError: hook teardown value must be function, received "boolean"

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions