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

webdriverio getText method and promises

hi i am using cucumber with webdriverio (with chai and chai-as-promised) - following test work - browser.getText('#copyright').to.eventually.equal('my text').and.notify(callback), but if i use element like h1 instead of '#copyright' than it does…
daljit
  • 1,256
  • 1
  • 11
  • 30
1
vote
1 answer

Karma with Mocha, Chai, Chai-as-promised and chai-sinon

I'm trying to get my Karma test suite running with Mocha, Chai, Sinon, Chai-as-promised and chai-sinon. It's currently set up with just mocha, chai and sinon framework. frameworks: ['mocha', 'requirejs', 'sinon', 'chai'] Now I've tried adding some…
Cuong
  • 127
  • 11
1
vote
1 answer

Returning a sinon stub from a sinon stub

I have problems getting a sinon stub to return/resolve another sinon stub. I am using sinon, chai, chai-as-promised and mocha. I am performing a number of async tasks in sequence and the code I want to test look something like…
liket
  • 193
  • 1
  • 8
1
vote
0 answers

(Appium - JavaScript - Mocha - Promises) Returns "{state:'pending'}" instead of element text

I am attempting to access the text within this element. Anytime I get the return value of the function or store the results in a variable, I get "{state:'pending'}" when printing to console. Does anyone have an idea of what I am doing incorrectly?…
Avyxyva
  • 11
  • 2
1
vote
3 answers

How to convert a promise in protractor to a string

I am a bit new to Protractor and Jasmine, and I am trying to check if a list of elements that I have fetched using getText() contains a particular element: Consider the following elements var productNameElements =…
Arjun Jhawar
  • 31
  • 1
  • 3
1
vote
0 answers

How do I make an assertion that the value of a callback eventually changes?

I'm currently trying to write a test that asserts that after I click on an element the value of another element eventually changes. I tried the following : it 'should change the value of the ec when the Scheduled option is clicked', -> …
CodePrimate
  • 6,646
  • 13
  • 48
  • 86
1
vote
1 answer

How do I handle an array of promises using Protractor w/ chai-as-promised

I am using Protractor with CucumberJS and chai-as-promised (given that CucumberJS does not have a built-in assertions library) to build an automated test suite. Everything works fine for single assertions (using the expect feature of…
0
votes
1 answer

chai-as-promised not failing typescript tests

I'm trying to use chai-as-promised in my Mocha test for some typescript code. I can't quite get the syntax right. So I setup a minimal reproducer: index.ts // Sample promise that resolves on red, fails on other values export const getRedColor =…
stwissel
  • 20,110
  • 6
  • 54
  • 101
0
votes
0 answers

How to get expect value from test case

I'm using Chai, mocha, karma for testing. I need to get the value of an expect. Something like this: var result = expect(data).to.eql(200); console.log('expected result', result) I need to get the status : success or error and if it is an error I…
0
votes
0 answers

Typescript Mocha Chai-As-Promised: how to test a function that can throw OR return a Promise

I'm testing a function to make sure it throws in certain situations. If the func doesn't throw it returns a Promise. For example: function foo() { if ( true ) throw new Error() return Promise.resolve() } describe( "", () => { it(…
Sean
  • 509
  • 2
  • 11
0
votes
1 answer

Chai + mocha, succeed in test if resolved, fail if rejected

I have a function that returns a promise. In my test file that is using chai I want the following to happen: const result = sendSurveyDataToAnalytics(userId,eventType,eventTitle) result.then(() => { Logger.info("Succeed in the test if we get…
Contentop
  • 1,163
  • 3
  • 20
  • 43
0
votes
2 answers

Mongoose Schema.index on multiple fields does not work with tests

I have created an uploadSchema (mongoose.Schema) with the fields (among the rest): key and bucket. each of them alone is not unique but together I want them to create a unique id. in my code, I used the line (right after declaring the uploadSchema…
0
votes
1 answer

Why is my expected rejection not a success case in mocha using chai-as-promise?

I want to assert a promise rejection in a mocha test case. Hence I do this in typescript: import { expect, use, } from "chai"; import * as chaiAsPromised from "chai-as-promised"; use(chaiAsPromised); describe("Promise rejection", async ()…
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
0
votes
0 answers

stub never called with sinon and nodejs using chai-as-promised

i'm facing a issue with my unit test, stuck completely, the code is simple, please need to understand what's going on, my stub is never called, the set seems to be correct, here the code: let strategy =…
Arthur
  • 27
  • 7
0
votes
3 answers

nodejs/mocha/chai as promise : variables used in expected async function initialized outside

I am brand new to mocha/chai and I spent 2 days trying to solve the following issue without any success (please note that the code below is just to present the concept, it is not the real one). I have got a JS file called "api.js" in which some…
Guilmort
  • 41
  • 1
  • 5