You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi coders!
I would like to test my middleware and in my case I use it to check if an input field value has correct pattern to display an error in case of not.
constconfigureMockStore=require('redux-mock-store').default;importvalidationMiddlewarefrom'./validationMiddleware';import{FORM_SET_ERROR}from'../../../lib/components/containers/form/store/constants';import{setFormValue}from'../../../lib/components/containers/form/store/actions';constmockStore=configureMockStore([validationMiddleware]);describe('Validation middleware',()=>{it('should dispatch error when wrong value for specific pattern',()=>{conststore=mockStore({form: {form: {field: {error: false,},},},});store.dispatch(setFormValue('field','123','^[a-zA-Z\-\'. ]*$'));constexpectedPayload={type: FORM_SET_ERROR,attr: 'field',error: true,};constactions=store.getActions();expect(actions).toEqual([expectedPayload]);});});
The point is that it dispatches another action in case of error so there are two different actions dispatched instead of one (FORM_SET_ERROR and FORM_SET_VALUE).
So I don't know how to check if the FORM_SET_ERROR was dispatched.
Any ideas?
Thank you in advance!
The text was updated successfully, but these errors were encountered:
Cicko
changed the title
Test with dispatch in middleware
Test with extra dispatched action in middleware
Sep 22, 2019
Hi coders!
I would like to test my middleware and in my case I use it to check if an input field value has correct pattern to display an error in case of not.
My ValidationMiddleware.js:
And my ValidationMiddleware.text.js:
The point is that it dispatches another action in case of error so there are two different actions dispatched instead of one (FORM_SET_ERROR and FORM_SET_VALUE).
So I don't know how to check if the FORM_SET_ERROR was dispatched.
Any ideas?
Thank you in advance!
The text was updated successfully, but these errors were encountered: