我一直在尝试从NX monorepo在lib中运行测试,但它不起作用。首先,它找不到类型,所以我添加了/// <reference types="@types/jest" />
,它被解决了。然后,当我运行测试时,我得到了错误:参考错误:jest未定义。Jest安装在monorepo的根目录下,我也尝试为lib安装jest,也删除了node_modules。对我来说没有任何效果。
/// <reference types="@types/jest" />
import { handleTokenAuthorization } from '.';
describe('auth funtions', () => {
it('Should mount and replace url correctly to login screen', () => {
const url = `${process.env.NX_APP_CLIENT_ID}/authorize?response_type=code&client_id=${process.env.NX_FRONT_URL}&scope=openid+profile&redirect_uri=${process.env.VITE_FRONT_URL}/receive-auth-token`;
const replaceFn = jest.spyOn(window.location, 'replace');
handleTokenAuthorization();
expect(replaceFn).toBeCalledWith(url);
});
});
1条答案
按热度按时间9ceoxa921#
我通过@nrwl/jest:jest切换了vitest,所以我从我的库中在project.json中添加了以下配置,测试运行器工作正常。