我有一个单元测试,它检查我的路由配置的值:
expect(route).toEqual(['', 'login']);
route
被定义为string | string[]
的联合类型
我已经尝试过类似的操作,但是不起作用:
expect(route as string[]).toEqual(['', 'login']);
茉莉花报告:
Expected value to equal:
["", "login"]
Received:
""
Difference:
Comparing two different types of values. Expected array but received string.
如何告诉茉莉花以字符串数组测试我的路由?
答案 0 :(得分:0)
如@ TitianCernicova-Dragomir所评论,该测试已正确编写。这里是一个简化的测试:
it('jasmine should interpret ts union types properly', () => {
let foo: string | string[] = ['1', '2'];
expect(foo).toEqual(['1', '2']);
});