3

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.com/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.

1 Answer 1

5

I'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)
            });
        });
    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.