Open sezanzeb opened 2 months ago
Writing
global.beforeEach = beforeEach
global.afterEach = afterEach
global.expect = expect
in the file that contains the tests helps as a workaround
I also had to add this workaround to my pre-loaded file.
bunfig.toml
:
[test]
preload = ["apps/__tests__/api/bun-preload.ts"]
bun-preload.ts
:
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { beforeEach, afterEach, afterAll, expect } from 'bun:test';
// @ts-ignore
global.beforeEach = beforeEach
// @ts-ignore
global.afterEach = afterEach
// @ts-ignore
global.afterAll = afterAll
// @ts-ignore
global.expect = expect
Which is less than ideal. Otherwise my test helpers using beforeEach
, afterEach
, etc.. will also fail with the same error reported by @sezanzeb
What is the problem this feature would solve?
I'm importing some utility functions for my tests that call
beforeEach
andafterEach
.Right now, the tests are failing with
Can't find variable: beforeEach
https://bun.sh/guides/test/migrate-from-jest says
However, this only seems to be the case in actual test files, but not in files that are imported.
What is the feature you are proposing to solve the problem?
Inject globals in imported files during tests
What alternatives have you considered?
No response