javascript - Chai: AssertionError: expected [Function] to be a function (when testing exceptions) -
i'm getting error assertionerror: expected [function] function
when i'm trying whether async function throws error
it('has invalid password', async () => { const fakedata = { email: userdata.email, password: 'something not password!.' } expect(async () => { await authservice.authenticate(fakedata) }).to.throw(errors.unauthenticatederror) })
result:
assertionerror: expected [function] function @ assertion.assertthrows (node_modules/chai/lib/chai/core/assertions.js:1273:32) @ assertion.ctx.(anonymous function) (node_modules/chai/lib/chai/utils/addmethod.js:41:25) @ doasserterasyncandaddthen (node_modules/chai-as-promised/lib/chai-as-promised.js:293:29) @ assertion.<anonymous> (node_modules/chai-as-promised/lib/chai-as-promised.js:252:17) @ assertion.ctx.(anonymous function) [as throw] (node_modules/chai/lib/chai/utils/overwritemethod.js:49:33) @ context.it (dist/tests/unit/auth-service.spec.js:56:20) @ test._mocha2.default.test.run (node_modules/mocha-http-detect/dist/index.js:84:21)
what did wrong?
this known issue happens when try pass async function.
to fix issue, can use chai canary.
more information: https://github.com/chaijs/chai/issues/958
Comments
Post a Comment