私は酵素、シロンを使用しており、私の反応成分を単体テストすることを期待しています。どのように反作用コンポーネントのコンストラクタをスパイするためにユニットテスト?
import React from 'react';
import expect from 'expect.js';
import { shallow } from 'enzyme';
import ExampleComponent from './../../../src/js/components/example-component';
describe('Test <ExampleComponent />', function() {
beforeEach(function() {
this._sandbox = sinon.sandbox.create();
this.constructorSpy = this._sandbox.spy(ExampleComponent.prototype, 'constructor');
});
afterEach(function() {
this._sandbox.restore();
this.constructorSpy = null;
});
it('Should set the state with the correct data [constructor]', function() {
const wrapper = shallow(<ExampleComponent />);
console.log(' - callCount: ', this.constructorSpy.callCount);
expect(this.constructorSpy.calledOnce).to.be(true);
expect(Immutable.is(wrapper.state('shownData'), Immutable.Map())).to.be(true);
});
コンポーネントのコンストラクタに、プロップとして渡すものに応じて状態を設定するロジックがあります。ただし、このテストでは、コンストラクターの呼び出し回数が0であり呼び出されていないことがわかります。
コンポーネントコンストラクタを偵察する正しい方法は何ですか?私は間違って何をしていますか?
サンドボックスに追加したい機能が他にもあるので、私はサンドボックスを使用しています。