I have a unit test which checks the string body of a fetch() call.
However, this test is a bit fragile because if the object structure changes one is left trying to look at two giant strings and seeing what is different.
Instead I want to refine this test to check if the object produced out of calling JSON.parse() on this is equivalent to another object and possibly, chain this with checking for certain object sub properties.
expect(global.fetch).toHaveBeenCalledWith(
'http://localhost:8080/api',
{
"body": JSON.stringify(expected_body),
"headers": {
"Content-Type": "application/json"
},
"method": "POST"
},
);
Note this is not asking for a deep equal to comparison check. My question really is about how to call a lambda function before running the matcher.
What is the best way to test this?