【发布时间】:2020-06-06 21:32:11
【问题描述】:
我在 Nest.JS 中有一个控制器可以重定向:
@Get('route/:value')
async route(@Param('value') value: string) {
const result = await this.someService.doSomethingWithValue(value);
if (result) {
return { url: 'http://example.com/success.html' };
} else {
return { url: 'http://example.com/fail.html' };
}
}
如何在 controller.spec.ts 中测试正确的重定向响应? 即:
describe('test', () => {
it('should show success page', async() => {
service.doSomethingWithValue = jest.fn(() => Promise.resolve(true));
expect(controller.route('value')).toBe(?????);
});
});
【问题讨论】:
标签: nestjs