Wie unit-Tests in diesem Redux thunk?

Also ich habe das Redux-action-Schöpfer, der mit redux thunk middleware:

accountDetailsActions.js:

export function updateProduct(product) {
  return (dispatch, getState) => {
    const { accountDetails } = getState();

    dispatch({
      type: types.UPDATE_PRODUCT,
      stateOfResidence: accountDetails.stateOfResidence,
      product,
    });
  };
}

Wie kann ich es testen? Ich bin mit der chai - Paket zum testen. Ich habe einige online-Ressourcen, aber ich bin nicht sicher, wie es weiter geht. Hier ist mein test bisher:

accountDetailsReducer.test.js:

describe('types.UPDATE_PRODUCT', () => {
    it('should update product when passed a product object', () => {
        //arrange
        const initialState = {
            product: {}
        };
        const product = {
            id: 1,
            accountTypeId: 1,
            officeRangeId: 1,
            additionalInfo: "",
            enabled: true
        };
        const action = actions.updateProduct(product);
        const store = mockStore({courses: []}, action);
        store.dispatch(action);
        //this is as far as I've gotten - how can I populate my newState variable in order to test the `product` field after running the thunk?
        //act
        const newState = accountDetailsReducer(initialState, action);
        //assert
        expect(newState.product).to.be.an('object');
        expect(newState.product).to.equal(product);
    });
});

Meine thunk nicht asynchrone Aktionen. Irgendwelche Ratschläge?

InformationsquelleAutor twilco | 2016-09-19
Schreibe einen Kommentar