【发布时间】:2021-07-20 00:02:22
【问题描述】:
我正在使用 Jest 为 ionic react 应用程序创建测试。
该应用是使用 create react app 创建的。
我为登录组件创建了一个基本测试:
import React from 'react';
import { render } from '@testing-library/react';
import Login from './Login';
test('renders without crashing', () => {
const { baseElement } = render(<Login />);
expect(baseElement).toBeDefined();
});
在登录组件中我有导入:
import { Storage } from '@ionic/storage';
我可以使用Storage 来处理存储,但是当我运行上面的测试时出现以下错误:
Test suite failed to run
Cannot find module '@ionic/storage' from 'src/pages/Login.tsx'
我正在使用 docker,并且该模块存在于 node_modules/@ionic/storage 中。
我搜索了很多,但到目前为止我没有找到解决方案。
【问题讨论】:
-
这有什么更新吗?我遇到了同样的问题。
-
还没有,很遗憾。我猜这是 npm 包的问题
-
尝试降级到 2.x 但那个只有角度支持:(
-
你在
@ionic中有storage文件夹在node_modules中吗? -
是的,我确实有那个文件夹,你可以在这里看到:imgur.com/KdPeXW9,你没有看到它吗?
标签: reactjs ionic-framework npm jestjs