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
3
votes
2 answers

How can I use rejectedWith to perform an exact match of the error message?

I've recently picked up the JS unit test libraries Mocha, Chai and Chai-As-Promise. However, I'm running into a situation where I'm not sure if it's a default behaviour or it's something I've missed. when I assert an error message rejected from a…
3
votes
1 answer

Why is this chai-as-promised AssertionError printing to the Console but not my Mocha test runner?

I'm tyring to test some code that uses Promises with chai-as-promised and Mocha. My test suite is also utilizing fetch-mock to mock AJAX requests that would normally be sent using the Fetch API. Here's the code I'm trying to test: /** * Sends a…
Nathan Jones
  • 4,904
  • 9
  • 44
  • 70
3
votes
0 answers

When using chai-as-promised can you get a line number w/ the failed assertion?

Using mocha + chai, when an AssertionError is thrown, I see this AssertionError: expected 2 to equal 4 + expected - actual -2 +4 at Context. (test/sync.coffee:116:18) When using chai-as-promised I see this 1)…
rissem
  • 503
  • 1
  • 5
  • 11
3
votes
2 answers

How does one use Q.all with chai-as-promised?

The chai-as-promised docs have the following example of dealing with multiple promises in the same test: it("should all be well", function (done) { Q.all([ promiseA.should.become("happy"), …
RichardTowers
  • 4,682
  • 1
  • 26
  • 43
3
votes
3 answers

Protractor with mocha and chai

I started using Protractor and the first thing I've tried to do is to use Mocha and Chai instead of Jasmine. Although now I'm not sure if that was a good idea. first I needed to make Chai accessible from all the spec files, without having to import…
iLemming
  • 34,477
  • 60
  • 195
  • 309
2
votes
1 answer

Why is my chai-as-promised rejected method not working?

I use mocha, chai, and chai-as-promised. The test should fail, but it doesn't, I don't know what's wrong, any suggestions? const { describe, it } = require('mocha') const chai = require('chai') const { expect } = require('chai') const chaiAsPromised…
Ibrahim
  • 33
  • 4
2
votes
3 answers

Mocha.js: async function breaks the nested structure

When testing a result of async function, using mocha, the tests that comes after await pops out of the nested structure, like the first 2 tests below: ✓ email ✓ phone current unit fetch data ✓ is 5==5 3 passing (10ms) How can we make the…
Dani-Br
  • 2,289
  • 5
  • 25
  • 32
2
votes
1 answer

Assertion error when testing async function with mocha and chaiAsPromised

So i am trying to test that my async function throws an error when I stub s3GetObject = Promise.promisify(s3.getObject.bind(s3)) to be rejected with blah however i am getting that my function is not async and it does not throw an error. below is my…
2
votes
1 answer

Is there a way to pass locator "by" as a string on protractor?

I'm trying to avoid using a switch-case to verify the locator and then creating an element. This is how my code looks like: switch (name.by) { case "class": return element(by.className(name.value)); case…
2
votes
1 answer

chai-as-promised should.eventually.equal not passing

I am trying to write a minimum working example of chai-as-promised in order to understand how it is working when testing functions that return a promise. I have the following function: simple.test = async (input) => { return input; }; and the…
ffritz
  • 2,180
  • 1
  • 28
  • 64
2
votes
0 answers

Chai-As-Promised passing test even when its throwing an error

public clickOnElementWithSelectionMethod(elementKey, selectionMethod, selectionValue) { let elementToClick = this.getWebElement(elementKey, selectionMethod, selectionValue); return assert.eventually.equal( elementToClick.click().then(()…
Niveditha Karmegam
  • 742
  • 11
  • 28
2
votes
2 answers

Protractor tests are passing but didn't execute the tests

I am new to java script protractor cucumber framework. I can see similar issue raised here an year ago but this was fixed in a protractor release an year ago as well. hence raising a new question. I am using latest version of cucumber, protractor,…
Navin
  • 273
  • 3
  • 15
2
votes
1 answer

Checking for presence of elements using Protractor and chai as promised

I am having trouble testing for the absence of elements in my node.js app. I have an enterBtn button that, when clicked, it displays resultsTable and a clearBtn. The enterBtn is always present. I am trying to test that the resultsTable disappears…
learningruby347
  • 211
  • 1
  • 4
  • 12
2
votes
0 answers

chai-as-promised types conflict with chai

I have unit tests that depend on chai and chai-as-promised (a library that extends Chai so you can easily test promises) This assertion: return expect(myPromise).to.eventually.equal(true) gives me compile error error TS2300: Duplicate identifier…
Jared
  • 2,978
  • 4
  • 26
  • 45
2
votes
1 answer

Chai (as promised) match property

How can I test a property against a regular expression in chai? Bonus points: I actually want to test a property of an object returned by a promise using chai-as-promised (but I guess if I know the non-promise way chai-as-promised should just work…
Lukas
  • 9,752
  • 15
  • 76
  • 120