Luc*_*tta 3 javascript typescript jestjs
我正在使用以下内容:
myFunction 返回一个如下所示的数组:
[
...
{
id: 00000000,
path: "www.someUrl.com/some/path/to"
}
...
]
Run Code Online (Sandbox Code Playgroud)
我想将它与以下类型的数组进行匹配:
const output = [
...
{
id: 00000000,
path: "path/some/path/to"
}
...
]
Run Code Online (Sandbox Code Playgroud)
简而言之:我想完全匹配 id,但只部分匹配路径。
但我只是不知道如何......我尝试了以下方法:
expect(myFunction()).toEqual(expect.arrayContaining(output));
Run Code Online (Sandbox Code Playgroud)
但这给了我一个错误。
我已经用以下代码解决了:
const output = JSON.parse(readFileSync('./myFunction.json', 'utf8'));
describe('Testing myFunction.', () => {
test('Deafult test.', () => {
const input = myFunction();
input.map((value, index) => {
const { imageURL, ...remaining } = output[index];
expect(value).toMatchObject({
...remaining,
imageURL: expect.stringContaining(imageURL)
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7248 次 |
| 最近记录: |