4

I'm using sinon / chai and some other plugins, I can test promises and their results, etc, but how can I ensure that a function returns a promsie?

I realize that if other tests pass (eg. when you run the rest with return or await and get expected result) it means it is a promise, but is there something along the lines of:

expect(foo).to.return.a('promise')

EDIT: Unfortunately the suggested post did NOT answer my question with unit testing, but I did figure out the answer:

let result = foo();
expect(result).to.be.a('promise');
Mankind1023
  • 7,198
  • 16
  • 56
  • 86
  • Possible duplicate of [How do I tell if an object is a Promise?](https://stackoverflow.com/questions/27746304/how-do-i-tell-if-an-object-is-a-promise) – laggingreflex Apr 16 '18 at 17:34
  • 2
    @laggingreflex this isn't a duplicate, the question is specifically about how you do this using chai – James Apr 16 '18 at 18:07
  • @mankind I suggest you post your solution as an answer rather than edit your question. – James Apr 22 '18 at 21:32

1 Answers1

1
expect(result instanceof Promise).to.be.eql(true)
Isolin
  • 845
  • 7
  • 20