获取引用错误:您正在尝试在Jest环境被拆除后import
一个文件。Used jest.useFakeTimers();进口后,但问题仍然存在。有什么办法解决吗?
下面是我的jest.config.ts
import type { Config } from "@jest/types"
const config: Config.InitialOptions = {
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
testRegex: '(/__test__/.*|(\\.|/)(test|spec))\\.[jt]sx?$',
moduleFileExtensions: [ 'js','ts'],
testEnvironment: "jest-environment-node",
fakeTimers: {
enableGlobally: true,
},
verbose: true
}
export default config
字符串
测试文件office.test.ts
import {ApolloServer} from 'apollo-server'
import {expect,test,jest} from '@jest/globals';
import officeGql from '../controllers/controller'
jest.useFakeTimers();
test('Office Module Test', async () => {
let typeDefs = officeGql.types
let resolvers = officeGql.resolvers
let testServer = new ApolloServer({
typeDefs,
resolvers,
});
const response = await testServer.executeOperation({
query: `query offices(limit: $limit,offset: $offset){name, address}`,
variables: { limit: 10,offset:0 },
});
expect(response.data).toBeTruthy();
});
型
1条答案
按热度按时间7cwmlq891#
该问题是一个开放句柄。要解决这个问题,你所要做的就是
字符串
这是一个临时修复,将工作时,我找到一个更好的方式,我会张贴它