【发布时间】:2022-07-28 16:58:02
【问题描述】:
如果中间件中的条件失败,我有一个 nuxt 页面会重定向用户,我想测试是否发生了重定向。
middleware({ $featureFlag, store, route, redirect }) {
if (!$featureFlag.isFeatureEnabled()) {
redirect(`/gfdgfd`);
}
},
但是,测试失败:
it('Should redirect to homepage when FT is turned off', () => {
const $featureFlag = { track: jest.fn(), isFeatureEnabled: () => false };
const redirect = jest.fn();
shallowMount(page, {
store,
redirect,
mocks: {
$route: { query: { token: {} } },
$auth: { checkSession: jest.fn() },
$featureFlag,
},
methods: {
getTokenPayload() {
return {};
},
},
});
expect(redirect).toBeCalled(); // THIS FAILS saying 'redirect' was called zero times
});
【问题讨论】:
标签: vue.js jestjs nuxt.js vue-test-utils