Added test for Redux actions

parent efa13327
import * as actions from './category';
import { CATEGORY_ACTION_TYPE } from 'redux/constants/ActionTypes';
const { CATEGORY_INIT_BEGIN, CATEGORY_INIT_SUCCESS, CATEGORY_INIT_FAILED } = CATEGORY_ACTION_TYPE;
describe('Category Actions - logic', () => {
describe('initCategory -logic', () => {
it('initCategory should be defined', () => {
expect(typeof actions.initCategory()).toBe('function');
});
it('should call redux dispatch', () => {
const initCallBack = actions.initCategory();
const mockDispatch = jest.fn();
initCallBack(mockDispatch);
expect(mockDispatch).toHaveBeenCalledWith({ type: CATEGORY_INIT_BEGIN });
});
});
});
import * as actions from './product';
import { PRODUCT_ACTION_TYPE } from 'redux/constants/actionTypes';
import API from 'services/api';
const { PRODUCT_INIT_BEGIN, PRODUCT_INIT_SUCCESS, PRODUCT_INIT_FAILED } = PRODUCT_ACTION_TYPE;
describe('Product Actions - logic', () => {
describe('getProductDetails -logic', () => {
it('getProductDetails should be defined', () => {
expect(typeof actions.getProductDetails()).toBe('function');
});
it('should call redux dispatch', () => {
const getProductDetailsSpy = jest.spyOn(API, 'getProductDetails');
getProductDetailsSpy.mockImplementation(() => Promise.resolve({}));
const mockDispatch = jest.fn();
const productCallBack = actions.getProductDetails('test');
productCallBack(mockDispatch);
expect(mockDispatch).toHaveBeenCalledWith({ type: PRODUCT_INIT_BEGIN });
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment