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
81
votes
15 answers

Verify that an exception is thrown using Mocha / Chai and async/await

I'm struggling to work out the best way to verify that a promise is rejected in a Mocha test while using async/await. Here's an example that works, but I dislike that should.be.rejectedWith returns a promise that needs to be returned from the test…
plexer
  • 4,542
  • 2
  • 23
  • 27
22
votes
4 answers

Testing rejected promise in Mocha/Chai

I have a class that rejects a promise: Sync.prototype.doCall = function(verb, method, data) { var self = this; self.client = P.promisifyAll(new Client()); var res = this.queue.then(function() { return self.client.callAsync(verb, method,…
cyberwombat
  • 38,105
  • 35
  • 175
  • 251
18
votes
2 answers

How to unit test a method which connects to mongo, without actually connecting to mongo?

I'm trying to write a test to test a method that connects to mongo, but I don't actually want to have to have mongo running and actually make a connection to it to have my tests pass successfully. Here's my current test which is successful when my…
Catfish
  • 18,876
  • 54
  • 209
  • 353
15
votes
4 answers

How to use chai-as-promised with Typescript?

I'm trying to use chai-as-promised package with TypeScript. First of all, the following code works well in simple JavaScript. import * as chai from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; chai.use(chaiAsPromised); const expect =…
12
votes
5 answers

Test async function to throw with mocha

I've got an async function which runs 2000ms and then it'll throw an exception. I am trying to test exactly this behaviour with Mocha / chai, but apparently I am doing it wrong. That's what I've…
kentor
  • 16,553
  • 20
  • 86
  • 144
12
votes
2 answers

How to test promises with Mocha

I'm using Mocha to test an asynchronous function that returns a promise. What's the best way to test that the promise resolves to the correct value?
Jo Liss
  • 30,333
  • 19
  • 121
  • 170
11
votes
5 answers

chai-as-promised: multiple expect statements in a single test

I'm using chai-as-promised to test some promises. My issue is I'm not sure how to have multiple expect statements in a single test. In order for the expect().to.be.fulfilled to work properly, I need to return it, like this: it('test', () => { …
ewok
  • 20,148
  • 51
  • 149
  • 254
9
votes
1 answer

Chai-As-Promised is eating assertion errors

I'm using chai-as-promised + mocha for writing some selenium-webdriver tests. Since webdriver extensively uses promises, I imagined it would be better if I used chai-as-promised for those type of tests. The problem is that when the tests fail, the…
kumarharsh
  • 18,961
  • 8
  • 72
  • 100
8
votes
1 answer

TypeScript and chai-as-promsied: eventually is an invalid property

I am trying to write my Cucumber tests using TypScript, like this: import { browser, $$ } from 'protractor'; import { Given, Then } from 'cucumber' import { expect } from 'chai'; Given('I navigate to the homepage', function (callback) { …
serlingpa
  • 12,024
  • 24
  • 80
  • 130
8
votes
3 answers

expecting promised to resolve or reject doesn't properly fail a test with mocha and chai-as-promised

Using Mocha and chai-as-promised, I'm trying to test that my promised are being resolved and rejected properly. But the expect functions given by chai-as-promised aren't properly causing the tests to fail. Example: test.js const chai =…
ewok
  • 20,148
  • 51
  • 149
  • 254
6
votes
2 answers

chai-as-promised tests don't work with $q promises

I'm trying to get chai-as-promised to work with $q promises with karma unit tests. svc.test = function(foo){ if (!foo){ // return Promise.reject(new Error('foo is required')); return $q.reject(new Error('foo is required')); }…
chovy
  • 72,281
  • 52
  • 227
  • 295
4
votes
1 answer

Testing if a promise throws/rejected with Mocha + Chai as promised doesn't seem to be working

I have an async function that depends on another async function and i'm testing if it'll throw an error when the url is wrong, it does throw the error and it is on the console. But the test keeps failing, however I write the syntax. I'm completely…
SebastianG
  • 8,563
  • 8
  • 47
  • 111
4
votes
1 answer

Chai-As-Promised passes even when it is wrong

const chaiAsPromised = require('chai-as-promised'); const chai = require('chai'); const expect = chai.expect; chai.use(chaiAsPromised); describe('[sample unit]', function() { it('should pass functionToTest with true input', function() { …
laiboonh
  • 1,377
  • 1
  • 9
  • 19
4
votes
3 answers

What is the difference between chai and chai as promised

What is the difference between chai and chai as promised in mocha framework while using protractor ?
Emna Ayadi
  • 2,430
  • 8
  • 37
  • 77
4
votes
1 answer

Protractor: catch AssertionError

I'm using Protractor with Chai as Promised in order to create a javascript-based testing tool and I'm getting the error AssertionError: expected 'http://localhost:8888/test/homepage.php' to equal 'http://localhost:8888/test/my_homepage.php' while…
Ema.jar
  • 2,370
  • 1
  • 33
  • 43
1
2 3 4 5 6 7 8