I'm using the following:
- Node.js: 9.8.0
- Jest: 22.4.2
There's an array like the following being returned from myFunction:
[
...
{
id: 00000000,
path: "www.someUrl/some/path/to"
}
...
]
And I want to match it against the following kind of array:
const output = [
...
{
id: 00000000,
path: "path/some/path/to"
}
...
]
In a nutshell: I want to totally match the id, but only partially the path.
But I just don't know how... I've tried the following:
expect(myFunction()).toEqual(expect.arrayContaining(output));
But the gives me an error.
I'm using the following:
- Node.js: 9.8.0
- Jest: 22.4.2
There's an array like the following being returned from myFunction:
[
...
{
id: 00000000,
path: "www.someUrl./some/path/to"
}
...
]
And I want to match it against the following kind of array:
const output = [
...
{
id: 00000000,
path: "path/some/path/to"
}
...
]
In a nutshell: I want to totally match the id, but only partially the path.
But I just don't know how... I've tried the following:
expect(myFunction()).toEqual(expect.arrayContaining(output));
But the gives me an error.
Share Improve this question asked Jul 6, 2018 at 2:58 Lucas Almeida CarottaLucas Almeida Carotta 5677 silver badges18 bronze badges1 Answer
Reset to default 5I've solved with the following code:
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)
});
});
});
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744403856a4572525.html
评论列表(0条)