typescript - 如果结合 saga 测试 (*.spec.ts) 和组件测试 (*tsx),使用 mocha 运行测试会超时
问题描述
我有一个项目,我在其中编写了测试:
包含 sagas 的打字稿文件
mySaga.test.ts
使用 redux-saga-test-plan 和 sinon 进行模拟
tsx 组件
MyComponent.test.tsx
当我在单独的测试运行中运行每种测试类型时,
spec: ["./test/**/*.test.ts"]
或者
spec: ["./test/**/*.test.tsx"]
他们都成功了。
但是,如果我在一次测试中一起运行所有测试
spec: ["./test/**/*.test.ts", "./test/**/*.test.tsx"]
现在,所有 saga 测试都因 mocha 的超时消息而失败。所有组件测试仍然成功。
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
我试过提高超时但没有成功。这是来自 saga 测试的示例测试代码:
describe("MyWonderfulSagas", () => {
let readStub: any;
describe("mySaga1", () => {
afterEach(() => {
readStub.restore();
});
it("should dispatch an action containing data from the local storage", () => {
readStub = sinon.stub(StorageHelper, "read").resolves(mockData);
return expectSaga(mySaga1)
.dispatch(DataActions.loadData())
.put({
type: DataActions.dataSet.type,
payload: mockData
})
.silentRun()
.then(result => {
sinon.assert.calledOnce(readStub);
});
});
});
});
被测试的 saga 看起来像这样(加载数据是另一个加载数据并调度结果的生成器函数):
export function* mySaga1(): SagaIterator {
yield takeEvery(DataActions.loadData.type, loadData);
}
有没有人遇到过这个问题?我需要在哪里寻找这个问题?在 redux-saga-test-plan 或 mocha 或...?
解决方案
推荐阅读
- css - 媒体查询问题仅在 978px
- c - C 中类型转换丢失的信息
- dompdf - dompdf 0.8.2 带有变量/代码 php 的 pdf 模板
- python - python对象的内存分配
- c - 在 linux 中 fork 和 exec 几个孩子
- c - 在可变大小的井字游戏网格中检查获胜的最有效方法是什么?
- javascript - 为什么“()=> this.tick()”和“this.tick()”不一样?
- ios - Swift NSFetchedResultsController Sections 总是返回 nil
- c# - 有人可以解释这里发生的 Parallel.ForEach 循环逻辑吗?
- python - 在 python 字典中的列表中搜索值