Questions tagged [chai-as-promised]

Chai as Promised is an extension for the Chai assertion library which adds the capability for assertions about promises.

Chai as Promised is an extension for the Chai assertion library which adds the capability for assertions about promises. It is compatible with any promises which follow the Promises/A+ specification.

116 questions
1
vote
1 answer

chai as promised test rejection timeout

How should I test the reject: return new Promise(function(resolve, reject){ models.users.find({ where: { email: email } }).then(function(result){ …
Alvin
  • 8,219
  • 25
  • 96
  • 177
1
vote
1 answer

Chai as promised eventually not waiting long enough in Protractor e2e tests against an Angular app

I'm using Protractor with Chai-as-promised for my newest Angular 4 app. I have only 2 e2e tests for now. One logging in an existant user, another signing up a new one. My signup logic will also login the newly created user if signup succeeds. Here's…
Jeep87c
  • 1,050
  • 16
  • 36
1
vote
1 answer

Mocha and Sinon Tests With Promises Timeout

I have the following code for my tests using Sinon and Mocha. Whenever I run these tests, I get the following back 0 passing (747ms) 8 pending 1 failing 1) Customer displays order Given that the order is empty "before each" hook for "will…
MadPhysicist
  • 5,401
  • 11
  • 42
  • 107
1
vote
1 answer

Is it possible to resolve and view the result of a promise while debugging a test in Protactor?

I am trying to debug a test in a CucumberJS/Protractor/Chai-as-promised stack. var tableDataRows = $('.example-table-under-test').$$('tr'); var dataToTest = tableDataRows.map(function(rows, index) { if (index > 0) { var cells = rows.$$('td'); …
anjunatl
  • 1,027
  • 2
  • 11
  • 24
1
vote
0 answers

How to use nockback with promises?

I am trying to use nockBack to automate my fixtures recording/playback with code that uses promises and chai-as-promised. But I can't figure out how to make the async nockBack work with it. context('sad path', () => { it('should reject the…
springloaded
  • 1,079
  • 2
  • 13
  • 23
1
vote
1 answer

Mocha test hangs when comparing mongoose object with an object

I'm using mocha and chai (with chai-as-promised) and I'm trying to test a mongoDB database using mockgoose. The model: var Campaign = new Schema({ //Schema here }); Campaign.statics.getOneById = function(id) { return this.findOne({_id: id…
dabn
  • 33
  • 1
  • 5
1
vote
1 answer

Chai-as-promised - expect with promise always transforms into an empty object

from the documentation of chai-as-promised (2 + 2).should.equal(4); // becomes return Promise.resolve(2 + 2).should.eventually.equal(4); expect({ foo: "bar" }).to.have.property("foo"); // becomes return expect(Promise.resolve({ foo: "bar"…
Ins
  • 808
  • 6
  • 13
1
vote
2 answers

Testing a function that calls a function that returns a promise

I have code in the following form: sut.methodtotest = param => { return dependency.methodcall(param) .then((results) => { return results; }); }; I want to test sut.methodtotest, but when I use chai, mocha, require,…
Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304
1
vote
0 answers

Chai as Promised: `rejectWith` for particular error messages

I have a function that can return a few possible rejected promises: Promise.reject({ a : 'x' }) // or Promise.reject({ b : 'y' }) // etc. I want Chai as Promised to only pass this test if a particular rejection message is…
Peter Becich
  • 989
  • 3
  • 14
  • 30
1
vote
1 answer

how to assert json returned from promise with chai?

I'm trying to write a test for a json returned from a promise. I created this simple code so you can try to reproduce: "use strict"; var chai = require("chai"); chai.should(); var chaiAsPromised = require("chai-as-promised"); var chaiJsonEqual =…
Yaron Yosef
  • 447
  • 3
  • 12
1
vote
1 answer

Protractor and Cucumber.js: expectations doesn't works as expected using promises with mocha

I have been trying to testing my angular app using protractor and cucumber, but when i use mocha for create a expectation when the expectation it's false the error spec doesn't show in the console. The relevant HTML for the route…
1
vote
1 answer

Using chai-as-promised and chai-bignumber together fails

The following call filestore.getBlockNumber.q(fileHash).should.eventually.bignumber.equal(blockNumber) Fails with AssertionError: expected { state: 'pending' } to be an instance of string, number or BigNumber
A F
  • 7,424
  • 8
  • 40
  • 52
1
vote
1 answer

chai-as-promised - doesn't seem to work with bluebird promises

I am trying to test a piece of code I wrote with bluebird promises, by using chai-as-promised. My method to be tested returns a promise rejection, as follows: /** * Creates a new user entry in the database. * @param {JSONObject} userData --…
Mopparthy Ravindranath
  • 3,014
  • 6
  • 41
  • 78
1
vote
1 answer

Test Promise chain ends in .catch (using Mocha / Chai as promised)

I've seen lots of info on testing Promise rejections, but wondering if anyone knows how to write a test that will fail if a promise chain doesn't end with a '.catch'? I'm trying to protect against swallowed errors. For example, this would pass the…
1
vote
0 answers

how to extend chai-as-promised with own assertions (properties and methods)

I'm using Chai + chai-as-promised with Mocha runner. By simple Chai, the extension with own assertions works like this: http://chaijs.com/api/plugins/#addProperty-section How should it look by using chai-as-promised?
ya_dimon
  • 3,483
  • 3
  • 31
  • 42