These are chat archives for dareid/chakram

20th
Jul 2016
racerbajs
@racerbajs
Jul 20 2016 11:52
What method should I be using to find a specific item in a json array? I have an array elements[100] in a json and have specified one element in my test. I want to see if that element exists in elements[]. I've tried using to.include.json and to.have.json , but the comparison fails. Webstorm comparison tool tells me that the full elements[] array was expected.
Daniel Reid
@dareid
Jul 20 2016 11:54
So at the moment we have the following issue to add a specific json array includes option: dareid/chakram#5
however it can be worked round at the moment by using a callback in the json assertion
then checking for the item being present using raw chai
racerbajs
@racerbajs
Jul 20 2016 11:57
ok I see. Thanks for the quick response!
racerbajs
@racerbajs
Jul 20 2016 12:52
Not sure I'm doing it correctly but I get: " Error: could not find path '{"id":"4d2f0caf-6aff-47a1-b55d-dac07dcd5c7c","name":"testName","type":"devices","parentId":null}' in object [{"id":"4d2f0caf-6aff-47a1-b55d-dac07dcd5c7c","name":"testName","type":"devices","parentId":null} "
Did it like this: return expect(response).to.have.json('{"id":"4d2f0caf-6aff-47a1-b55d-dac07dcd5c7c","name":"testName","type":"devices","parentId":null}', function(data) {
expect(data).to.deep.equal(expectedElement);
});
Daniel Reid
@dareid
Jul 20 2016 13:01
So the first parameter is an optional path in the json object.
If u want to assert equality you can avoid the callback
If u want to run some code on the entire json, you can just provide the callback with no path
racerbajs
@racerbajs
Jul 20 2016 13:04
ahh geez. Ok so it's working now..
Cheers Daniel
Daniel Reid
@dareid
Jul 20 2016 13:05
No problem, let me know if u have any other questions
racerbajs
@racerbajs
Jul 20 2016 13:07
cool, thanks a lot :)