小编Iva*_*ych的帖子

柴:AssertionError:预期[Function]是一个函数(在测试异常时)

我在AssertionError: expected [Function] to be a function尝试异步函数是否引发错误时遇到此错误

it('has invalid password', async () => {
    const fakeData = { email: userData.email, password: 'something but not the password!.' }
    expect(async () => { await authService.authenticate(fakeData) }).to.throw(errors.UnauthenticatedError)
})
Run Code Online (Sandbox Code Playgroud)

结果:

AssertionError: expected [Function] to be a function
  at Assertion.assertThrows (node_modules/chai/lib/chai/core/assertions.js:1273:32)
  at Assertion.ctx.(anonymous function) (node_modules/chai/lib/chai/utils/addMethod.js:41:25)
  at doAsserterAsyncAndAddThen (node_modules/chai-as-promised/lib/chai-as-promised.js:293:29)
  at Assertion.<anonymous> (node_modules/chai-as-promised/lib/chai-as-promised.js:252:17)
  at Assertion.ctx.(anonymous function) [as throw] (node_modules/chai/lib/chai/utils/overwriteMethod.js:49:33)
  at Context.it (dist/tests/unit/auth-service.spec.js:56:20)
  at Test._mocha2.default.Test.run (node_modules/mocha-http-detect/dist/index.js:84:21)
Run Code Online (Sandbox Code Playgroud)

我做错什么了?

javascript node.js chai

5
推荐指数
2
解决办法
2778
查看次数

标签 统计

chai ×1

javascript ×1

node.js ×1