Suppose the following JSON is expected as part of a Frisby test:
{
array: ["1", "2", "3"]
}
The array of strings may return in any order, say ["3", "1", "2"]
.
How can I expect the above defined array without expecting an order?
I have tried
.expectJSON('array.?', "1")
.expectJSON('array.?', "2")
.expectJSON('array.?', "3")
but this is not valid syntax and the following error occurs:
TypeError: Expected valid JavaScript object to be given, got undefined
I went into the same problem, and finally figure this out. Using .afterJSON(), you will be able to use Jasmine's expect-syntax to do all the validation you want on the JSON object.
For your example, the script will look like this:
.afterJSON(function(json){
expect(json.array).toContain('1');
expect(json.array).toContain('2');
expect(json.array).toContain('3');
})