Skip to content

Instantly share code, notes, and snippets.

@simonewebdesign
Created February 24, 2015 09:50
Show Gist options
  • Save simonewebdesign/0e1fd75b0860ae8951b3 to your computer and use it in GitHub Desktop.
Save simonewebdesign/0e1fd75b0860ae8951b3 to your computer and use it in GitHub Desktop.
Chai expectations and Sinon.js (test spies) example checking if an object contains a certain key/value pair
it('will POST data in JSON format', () => {
let promise = ajax('POST', '/somewhere', {foo: "bar"})
.then((result) => {
expect(result).to.equal('OK');
});
expect(requests[0].requestBody).to.equal(JSON.stringify({foo: "bar"}));
requests[0].requestHeaders.should.have.property("Content-Type").with.length("application/json;charset=utf-8".length);
assert.propertyVal(requests[0].requestHeaders, "Content-Type", "application/json;charset=utf-8");
expect(requests[0].requestHeaders).to.have.property("Content-Type", "application/json;charset=utf-8");
requests[0].respond(200, {}, 'OK');
return promise;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment