dareid / chakram

REST API test framework. BDD and exploits promises
http://dareid.github.io/chakram/
MIT License
908 stars 99 forks source link

JsonSchemaAssert #105

Closed afcbpeter closed 7 years ago

afcbpeter commented 7 years ago

Hi,

Fairly new to JS and chakram, Im currently trying to assert that a json file matches the json I'm calling back from my api. I've made gradual progress but can't seem to get over the line. It's currently looking like this.

https://gist.github.com/afcbpeter/9c8dbdf8ffae804748fdc6572be5a7ae

The error Im currently getting is this

1) does valid assertion

0 passing (330ms) 1 failing

1) does valid assertion: AssertionError: expected { Object (error, response, ...) } to deeply equal [ Array(4) ]

Not quite sure where I've gone wrong.

harryrose commented 7 years ago

Hi, @afcbpeter. Have you seen the documentation on checking the json returned in a response? http://dareid.github.io/chakram/jsdoc/module-chakram-expectation.html#.json

afcbpeter commented 7 years ago

Hi @harryrose Yeah I looked through that initially I managed to do the headers just struggling with the full json file now.

harryrose commented 7 years ago

I'm assuming at the moment that the json in the ../../test/fixtures/test.json file does actually match the data that's being returned by the API (and that that data is in fact json).

The reason I linked to the above URL is to point out the json function (as opposed to eql, which is what is being used in your gist). Note the example in the documentation:

var response = chakram.get("http://httpbin.org/get");
    expect(response).to.comprise.of.json({
        url: "http://httpbin.org/get",
        headers: {
            Host: "httpbin.org",
        }
    });

applying that to your gist would result in something like:

var response = chakram.get("http://example.com");
    return expect(response).to.have.json(testFile);
afcbpeter commented 7 years ago

Thank you! Sorry for the inconvenience :)