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

Correct moment to call $rootScope's $apply/$digest method in a test

Angular testing docs shows an test sample where $apply is called before testing assertions. I tried to do the same but my test is not working properly. The first code that should break, works... it seems that my assertion is not running. The second…
armoucar
  • 408
  • 1
  • 4
  • 15
0
votes
1 answer

Expect and should use the Promise object instead of the resolved result

I have the following setup for my unit testing: const mocha = require('mocha') var chai = require('chai') var chaiAsPromised = require('chai-as-promised') chai.use(chaiAsPromised) var expect = chai.expect chai.should() describe('chain test',…
t.niese
  • 39,256
  • 9
  • 74
  • 101
0
votes
1 answer

testing a function that has been returned by a promise - checking for errors

I am testing a a function that is returned as a part of a promise. I'm using chai-as-promised. I'm able to test that the function works but I am unable to test that it throws errors properly. The function I'm trying to test, leaving out lots of…
Finnnn
  • 3,530
  • 6
  • 46
  • 69
0
votes
2 answers

Protractor: browser.isElementPresent() gives both true and false

I am working with a Protractor and Cucumber to test a React project. In the course of this I have some elements that will have visibility:hidden/visible and I would like to use Protractor's isDisplayed or isPresent to test with. I wrote a little…
CraftyViking
  • 1
  • 1
  • 5
0
votes
0 answers

Need help understanding performance of native promises versus Blubird

Background: I am writing a meteor app which initially populates a db with data retrieved via SOAP requests made to a API end point on a server somewhere. The initial request is a search via a search term I select. I get back a list of id's to…
timebandit
  • 794
  • 2
  • 11
  • 26
0
votes
1 answer

How do you wait for a promise using protractor and Chai?

I'm trying to wait for a promise resolution using Cucumber, Chai, and Protractor. Is there a way using Chai to wait for something (like a pageload) to occur before sending the callback? I want something like: browser.get(url).then(callback) which I…
user3554664
  • 349
  • 2
  • 16
0
votes
1 answer

Test return value from promise in chai

I have the following promises. I know they are working correctly, as the console.log output in funcThree returns the correct data. How do I prove this through testing? Basically, how do I test this promise? I have tried to tests below, but no matter…
Tori Huang
  • 527
  • 1
  • 7
  • 25
0
votes
3 answers

Implementing callbacks in javascript

I have a function in my helper js file to upload files on S3: module.exports.uploadToAWS = function uploadToAWS(folderName, fileName, fileData) { var s3 = new AWS.S3({ params: {Bucket: ‘myBucket’} }); var keyName = folderName + "/" +…
Firdous
  • 4,624
  • 13
  • 41
  • 80
0
votes
0 answers

Protractor e2e, chaijs and doSomethingAsync().should.eventually.equal("foo") - TypeError: Cannot read property 'should' of undefined"

It would be helpful to be able to do as chaijs says in their doc: return doSomethingAsync().should.eventually.equal("foo"); This would speed up writing my e2e tests as I wouldn't have to explicitly resolve the promises like this: // I wouldn't have…
pelican
  • 5,846
  • 9
  • 43
  • 67
0
votes
1 answer

Protractor Mocha-Allure-Reporter : Only the first "expect" failure for a testcase is logged in the report

I'm using protractor with mocha-allure reporter. In a test, when multiple "expect" statements are there,only the first "expect" statement result gets logged in the report.Please find sample code below var chai = require('chai'); var chaiAsPromised =…
jsan
  • 1
  • 3
0
votes
1 answer

Wait for unheld promise with Mocha

I'm trying to test a JavaScript object with Mocha using chai, chai-as-promised, sinon, sinon-chai and sinon-as-promised (with Bluebird). Here is the object under test: function Component(MyService) { var model = this; model.data = 1; …
Mouz
  • 273
  • 2
  • 13
0
votes
1 answer

How do I test with chai-as-promised a rejected promise and the error message?

I'm trying to check the error message on a rejected promise and if I make the message string wrong in the test it still passes. MyService.doSomething({ id: 12345 }).should.eventually.be.rejectedWith(TypeError, 'no attr foo defined2'); …
chovy
  • 72,281
  • 52
  • 227
  • 295
0
votes
1 answer

How do I simulate a delay with chai-as-promised and karma/angular?

Example test faking a delayed promise resolve: describe('Example', function() { var $q; var $rootScope; var $scope; var $timeout; var fakePromise; beforeEach(inject(function (_$q_, _$rootScope_, _$timeout_) { $q = _$q_; …
chovy
  • 72,281
  • 52
  • 227
  • 295
0
votes
1 answer

How can I test that a Promise is never fulfilled?

I'm testing a library I wrote to throttle execution of a function. The API is throttler.do(fn) and it returns a promise of fn's return value (resolved at whichever point the throttler decides it's ok to run it). I'm using lolex to fake Date() and…
user3099140
0
votes
1 answer

How to check promise value and property updated in promise but not returned with chai-as-promised

I have a promise which checks if I'm authorized or not (returning true or false). Within that promise, when authorization is false, I'm also adding the 403 statusCode to the response object that I pass as a parameter. I'm testing the result of my…
Bianca
  • 382
  • 4
  • 12