2017-04-14 5 views
2

私は非同期関数がエラーチャイ:AssertionErrorが:予想[機能](例外をテストする)関数であると

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を取得しています:

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カナリアを使用できます。

詳細情報:https://github.com/chaijs/chai/issues/958

+0

おかげで、それは良い考えです。 chai @ canaryはchai <4で動作するようにロックされているため、残念ながらchai @ canaryに更新することはできません。 –

+0

@Kossgreimおそらくモジュールのpackage.jsonのpeerDependenciesフィールドを変更してみてください。 – skiilaa

関連する問題