スパイのプロパティを使用しようとしましたが、このエラーで終了します。TypeError:expect.createSpyが関数ではありません
var spy = expect.createSpy();
spy();
expect(spy).toHaveBeenCalled();
エラー:
TypeError: expect.createSpy is not a function
スパイのプロパティを使用しようとしましたが、このエラーで終了します。TypeError:expect.createSpyが関数ではありません
var spy = expect.createSpy();
spy();
expect(spy).toHaveBeenCalled();
エラー:
TypeError: expect.createSpy is not a function
chai
あなたはSinonのようなライブラリを必要とするため、スパイを提供していません。
2の有用な組み合わせを作成しsinon-chai
呼ばチャイプラグインがあります:
const chai = require('chai');
const sinon = require('sinon');
const sinonChai = require('sinon-chai');
const expect = chai.expect;
chai.use(sinonChai);
// Create the spy, using Sinon.
let spy = sinon.spy();
// Call the spy, so we can test it.
spy();
// Assert that the spy has been called.
expect(spy).to.have.been.called;
あなたが実行しているexpect
のバージョン? GitHubのページごとに、expect
はあなたがV21を実行している場合は冗談に寄付されています+あなたはhereは、次のコードを使用します@通常のexpect.createSpy()
フォローインストール手順の代わりに冗談モック機能jest.fn()
を使用する必要があります、あなたは問題ないはずです。
var spy = jest.fn();
spy();
expect(spy).toHaveBeenCalled();
「期待」とは何ですか? – robertklep
ここから見つける:http://chaijs.com/api/bdd/ –
https://github.com/mjackson/expect/で問題が発生しています。 –