【发布时间】:2021-10-18 23:20:50
【问题描述】:
我刚开始使用带有 .spec.js 后缀的文件来测试带有 Jest 的文件,所以希望这不是一个愚蠢的问题。我没有通过 Google + Stackoverflow 研究发现任何东西。
我想使用 jest 检查包含新 window.location 的 if else 条件。
这是我的文件.ts
export const loadBSection = (bSectionId: string) => async (
dispatch: Dispatch,
getState: GetState,
{ bSectionApi }: Deps,
) => {
try {
...
} catch (e) {
dispatch(setBSectionErrorMessage(e.message));
if (e.response.status === 404) {
window.location.href = '/page-not-found.html';
}
}
};
我的文件.spec.ts
it('should .. and forward to a 404 page', async () => {
...
expect(store.getActions()).toEqual([setBSectionLoading(true), setBSectionErrorMessage(errorMessage)]);
// TODO what is expected here?
});
你有什么想法吗?
由于我是新手,也许您有一些深入研究的资源?
我使用:https://create-react-app.dev/docs/running-tests/ 作为介绍。 您是否还有其他资源可以帮助您将来找到一些文档?
【问题讨论】:
标签: reactjs typescript unit-testing jestjs ts-jest