2017-04-14 44 views
2

我得到這個錯誤AssertionError: expected [Function] to be a function當我試圖將異步函數是否拋出一個錯誤柴:Asse田:預計[功能]是一個函數(測試異常時)

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) 
}) 

結果:

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) 

我做錯了什麼?

+0

https://github.com/chaijs/chai/issues/958 – robertklep

回答

3

這是在嘗試傳遞異步函數時發生的已知問題。

要解決此問題,您可以使用Chai canary。

的更多信息:https://github.com/chaijs/chai/issues/958

+0

謝謝,這是一個好主意。不幸的是,我不能更新到chai @ canary,因爲chai-as-promise被鎖定與chai <4. –

+0

@Kossgreim一起嘗試更改模塊的package.json中的peerDependencies字段也許? – skiilaa