user2643864 user2643864 - 4 months ago 10x
AngularJS Question

How to see if a Promise contains specific data using Chai assertions

I've started using the Chakram Rest API testing framework which utilizes the Chai assertion library. In my code below Chakram.get returns a Promise. I can't seem to figure out how to see if this promise contains what I am specfically looking for. For example, Chakram.get should've got back the following string:


I simply want to see if it contains "category1".

var chakram = require('chakram'),
expect = chakram.expect;


describe("Categories", function() {
it("should return the list of categories for devices that are installed in the project", function () {
var response = chakram.get("");
return chakram.wait();

As you can see, I've tried the above to.contain line but get the following exception. I assume it is because Chai doesn't like the object type. Not sure if I need to convert the Promise to a different object type? If so, how?

TypeError: obj.indexOf is not a function
at include (/Users/acme/node_modules/chai/lib/chai/core/assertions.js:228:45)
at /Users/acme/node_modules/chakram/node_modules/chai-as-promised/lib/chai-as-promised.js:304:26
at _fulfilled (/Users/acme/node_modules/chakram/node_modules/q/q.js:834:54)
at self.promiseDispatch.done (/Users/acme/node_modules/chakram/node_modules/q/q.js:863:30)
at Promise.promise.promiseDispatch (/Users/acme/node_modules/chakram/node_modules/q/q.js:796:13)
at /Users/acme/node_modules/chakram/node_modules/q/q.js:604:44
at runSingle (/Users/acme/node_modules/chakram/node_modules/q/q.js:137:13)
at flush (/Users/acme/node_modules/chakram/node_modules/q/q.js:125:13)


I think you are looking for response.body


here is an example with the full promise:

  it("should support sequential API interaction", function () {
    return chakram.get("url")
    .then(function (response) {