Replies: 1 comment
-
Received some useful resources to read on this topic, thus closing now. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello Geeks,
I'm novice to jest and have just start to practice.
I'm trying to implement some jest based typescript e2e test cases for api calls. Upon receiving the http response in the form json object we need to the test script to validate the array objects that comes as part of the response. While executing the test case I'm seeing the it expects to validate the whole content of the array to be present where it's enough to validate only few elements in the array and returns a test failure result which doesn't make much sense to me. Let me try to explain with an example.
Suppose if my test script looks like below to validate only certain elements in an array object in a json object.
Test written to validate one part i.e the array object would be as follows,
expect(getResponse.data).toEqual(
expect.objectContaining({
testing_element: {
activeStatus: false,
Properties: expect.arrayContaining([
expect.objectContaining({
configId: expectedsettingId,
Properties: expect.objectContaining({
Label: 'Saved Settings’,
}),
}),
]),
},
})
);
Result would be like this.
Received + 18
"testing_element": Object {
}
Why the received item is validated on the entire array while we want to validate only to the expected elements value is available in the array or not? Can anyone please add more clarity on this, How this works and what to read more to understand here. How to validate only the wanted array elements and the whole array?
More specifically, we want to ensure only the configIds in both of the above array is present in the received output array or not? A help to understand much about this is highly appreciated. Thanks.
Beta Was this translation helpful? Give feedback.
All reactions