1

I'm using Chai.js and chai-as-promised to test some of my promise-returning library functions. I was stuck testing exceptions thrown from such a function because it turns out that the expect() function can also invoke a function rather than just examine the return value of a function and I was passing in the wrong thing.

See: https://stackoverflow.com/a/21587239/562139

(1) Is this documented somewhere? I couldn't find anywhere in the Chai.js documentation/page where it indicates that the expect API could take both values and functions that are executed before being tested/asserted upon.

(2) Where in the chai.js library source is the test for whether the argument to expect is a function, causing the function to be invoked before the tests?

pynexj
  • 19,215
  • 5
  • 38
  • 56
scorpiodawg
  • 5,612
  • 3
  • 42
  • 62

1 Answers1

1

Expect function doesn't expect a function as argument. It's throw implementation that expect a function to evaluate

The code is here for the function and assertion

Troopers
  • 5,127
  • 1
  • 37
  • 64
  • No, you must pass a function as argument to `expect` but the expectation is done in the implementation of `throw` and not in the implementation of `expect` – Troopers Mar 28 '18 at 06:48