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
2
votes
1 answer

Do I really need to return a promise in test when using Chai as Promised?

Chai as Promised documentation states as follows: Notice: either return or notify(done) must be used with promise assertions. And the examples on the site are as follows: return…
Bren
  • 2,148
  • 1
  • 27
  • 45
2
votes
0 answers

how to handle element.all(locator).each(eachFunction) in chai as promised

I am using Protractor, Cucumber, and Chai-As-Promise I try to test a search field, and verify the each search result contains the search input value. My prototype works great when Chai and Chai-As-Promised are used. Here is the test case: user…
Debbie
  • 21
  • 2
2
votes
1 answer

Deep equal using promises in Chai.js (testing)

I'm using Chai for my test and I want to deep compare the returned object from a promise. I tried this approach: expect(promise).to.eventually.eql(object) expect(promise).deep.equals(object) expect(promise).should.eventually.equal(object) But it…
Charlires
  • 863
  • 1
  • 11
  • 30
2
votes
1 answer

Expects aren't working in Chai as Promised results

I'm new to Promises in JavaScript, and whilst it seems to be working for me to an extent, I'm unable to test the 'reject' value. I'm passing through an Error, and want to ensure that it is an error and more importantly, that the error code matches…
Brody McKee
  • 203
  • 3
  • 5
2
votes
1 answer

chai.assert.isRejected Message validator not working

I'm attempting to write the following test: return chai.assert.isRejected(quote.validate(), 'Amount is not valid number'); When running this test, it is successful but upon fudging it to ensure it fails with the following, it still passes: return…
Conner McNamara
  • 365
  • 1
  • 5
  • 15
2
votes
2 answers

Protractor, Cucumber and chai as promised: When chai assertion fails

I am using protractor to run my cucumber tests. Inside my test I have the following assertion: label.getText().then( function(labelText){ labelText = labelText.trim(); console.log('label text:…
Jenninha
  • 1,357
  • 2
  • 20
  • 42
1
vote
1 answer

Mocha/Chai/ChaiAsPromised : expect(promise).eventually not waiting for resolution

I've got a function I want to test. It returns a promise. Here'a fake version that just waits a bit and then resolves the promise. function testee(){ let myPromise = new Promise( (resolve, reject) => { setTimeout( () => { …
djna
  • 54,992
  • 14
  • 74
  • 117
1
vote
1 answer

Using a custom chai method assertion with chai-as-promised

I want to add a custom assertion/method like this: chai.use(function (chai, utils) { var Assertion = chai.Assertion; Assertion.addMethod("convertToStringEqual", function (input) { new…
1
vote
2 answers

How to validate thrown javascript exception using chai and mocha?

I have MongoDB Query function which in which query params are validated Here is the function Note: user is mongoose model function fetchData(uName) { try{ if(isParamValid(uName)) { return…
Krunal Sonparate
  • 1,122
  • 10
  • 29
1
vote
0 answers

Firebase and Typescript: Setting reference to admin.database() causes mocha tests to hang

I'm using mocha, chai, and chaiAsPromised to test Firebase functions. I've been having a problem with my tests hanging: they run and succeed or as expected, but they don't complete. That is, I have to actually kill the test process to (Ctrl-C or F5)…
1
vote
1 answer

Sinon Stub gives unexpected UnhandledPromiseRejectionWarning

I have a function like so: static async performDatabaseConnectivityHealthCheck(logger) { let con; let ret; try { con = mysql.createConnection({ host: config.db.host, user: config.db.user, …
Dave Chambers
  • 2,483
  • 2
  • 32
  • 55
1
vote
1 answer

Electron,Spectron: how to write test cases in seperate javascript file

I am testing electron application use these technologies, Spectron, Chai, chai as promised I want to write my test cases in separate file, except all in one file. Here's what I've tried, describe("Login", function () { this.timeout(10000); …
1
vote
1 answer

chai as promised deep property test

I have a function that inserts into a table and returns a Promise. I am testing with chai-as-promised that duplicate inserts are rejected. What I want to test is the rejection, and the reason code. When I run the function and log…
Jordan.J.D
  • 7,999
  • 11
  • 48
  • 78
1
vote
0 answers

Check a property in the response object resolved by supertest using chai-as-promised

How do I check for the body property using chai-as-promised? I'm trying to access the body of the response as highlighted in the SuperAgent docs, but the assertion for .should.have.property('res') fails. I console.log(res) in a separate test and…
Extreme112
  • 95
  • 1
  • 2
  • 9
1
vote
1 answer

Mocha single test with promises fails and passes at the same time

I am currently writing some tests in a legacy system and am confused about a test result here. I have one test here which fails as expected but mocha shows as a result 1 passing and 1 failing. I am using Bluebird Promises, mocha, chai-as-promised…
Vegaaaa
  • 474
  • 4
  • 22