dimanche 28 juin 2020

How do I test if action is being called in redux

enter image description hereCurrently I want to test if this action is being called, and the reason is because this action only empty the array. So in order to test this action function I want to check if this is being called once. So I was thinking of using toHaveBeenCalled(1). Not sure if this is the right one to use that in here.

import * as actions from '../actions/index';
import { types } from '../actions/index';
import { fixedApi } from '../mock/mockAPI';

describe('actions', () => {
    it('should create an action and check if action named clearArray is being called', () => {
        
        const expectedAction = {
            type: types.CLEAR_ARRAY
        }
        expect(actions.clearArray()).toHaveBeenCalled()
        
    });
})

Aucun commentaire:

Enregistrer un commentaire