テスト中のモジュール内のメソッド呼び出しを置き換えるために使用しようとしてproxyquire
いますが、スタブが設定されているにもかかわらず、メソッドをそのまま呼び出しています。私は何を間違っていますか?
formsReducer.test.js:
import { expect } from 'chai';
import * as actions from '../actions/formsActions';
import * as types from '../constants/actionTypes';
import proxyquire from 'proxyquire';
describe('Forms Reducer', () => {
describe('types.UPDATE_PRODUCT', () => {
it('should get new form blueprints when the product changes', () => {
//arrange
const initialState = {
blueprints: [
{
id: 1,
categoryId: 1,
identifier: null,
name: "Investment Policy Statement",
sortGroup: 1,
wetSignRequired: false
}
]
};
const testBlueprints = [{ id: 999, categoryId: 1, name: "Form Blueprint Loaded From Product ID 1", sortGroup: 1, wetSignRequired: false }];
//use proxyquire to stub call to formsHelper.getFormsByProductId
let formsReducer = proxyquire.noCallThru().load('./formsReducer', {
formsHelper: {
getFormsByProductId: id => { return testBlueprints }
}
}).default;
const action = {
type: types.UPDATE_PRODUCT,
product: {
id: 1,
accountTypeId: 1,
officeRangeId: 1,
additionalInfo: "",
enabled: true
},
};
//act
const newState = formsReducer(initialState, action);
//assert
expect(newState.blueprints).to.be.an('array');
expect(newState.blueprints).to.equal(testBlueprints);
});
});
});
formsReducer.js:
import * as types from '../constants/actionTypes';
import objectAssign from 'object-assign';
import initialState from './initialState';
import formsHelper from '../utils/FormsHelper';
export default function formsReducer(state = initialState.forms, action) {
switch (action.type) {
case types.UPDATE_PRODUCT: {
let formBlueprints = formsHelper.getFormsByProductId(action.product.id);
formBlueprints = formsHelper.addOrRemoveMnDisclosure(formBlueprints, action.stateOfResidence.id);
return objectAssign({}, state, {blueprints: formBlueprints, instances: []});
}
}
formsHelper.getFormsByProductId
testBlueprints
を介して適切にスタブされた場合、正常に返されませんproxyquire
。私は何を間違っていますか?