Best JavaScript code snippet using best
config_thunks.tests.js
Source:config_thunks.tests.js
1import expect, { createSpy, restoreSpies } from 'expect';2import { find } from 'lodash';3import ReduxConfig, { configSchema } from '../src/config';4import reduxMockStore from './redux_mock_store';5import stubs from './stubs';6const schemas = {7 USERS: configSchema('users'),8};9const userStub = stubs.users.valid;10const store = {11 errors: {},12 data: {},13 loading: false,14};15const standardError = {16 status: 422,17 message: {18 message: 'Unauthenticated',19 errors: [20 {21 name: 'base',22 reason: 'User is not authenticated',23 },24 ],25 },26};27const parseServerErrorsFunc = (response) => {28 const error = response.message.errors[0];29 const errorResponse = { http_status: response.status };30 errorResponse[error.name] = error.reason;31 return errorResponse;32};33describe('ReduxEntityConfig - thunks', () => {34 describe('#create', () => {35 afterEach(() => restoreSpies());36 const apiResponse = [userStub];37 describe('successful call', () => {38 const createFunc = createSpy()39 .andCall(() => Promise.resolve(apiResponse));40 const config = new ReduxConfig({41 createFunc,42 entityName: 'users',43 schema: schemas.USERS,44 });45 const mockStore = reduxMockStore(store);46 it('calls the createFunc', () => {47 const params = { first_name: 'Mike' };48 return mockStore.dispatch(config.actions.create(params))49 .then(() => {50 expect(createFunc).toHaveBeenCalledWith(params);51 });52 });53 it('dispatches the correct actions', () => {54 return mockStore.dispatch(config.actions.create())55 .then(() => {56 const dispatchedActions = mockStore.getActions();57 const dispatchedActionTypes = dispatchedActions.map((action) => { return action.type; });58 const successAction = find(dispatchedActions, { type: 'users_CREATE_SUCCESS' });59 expect(dispatchedActionTypes).toInclude('users_CREATE_REQUEST');60 expect(dispatchedActionTypes).toInclude('users_CREATE_SUCCESS');61 expect(dispatchedActionTypes).toNotInclude('users_CREATE_FAILURE');62 expect(successAction.payload).toEqual({63 data: {64 sortedIds: [userStub.id],65 users: {66 [userStub.id]: userStub,67 },68 },69 });70 });71 });72 });73 describe('unsuccessful call', () => {74 const createFunc = createSpy()75 .andCall(() => Promise.reject(standardError));76 const config = new ReduxConfig({77 createFunc,78 entityName: 'users',79 parseServerErrorsFunc,80 schema: schemas.USERS,81 });82 it('calls the createFunc', () => {83 const mockStore = reduxMockStore(store);84 const params = { first_name: 'Mike' };85 return mockStore.dispatch(config.actions.create(params))86 .catch(() => {87 expect(createFunc).toHaveBeenCalledWith(params);88 });89 });90 it('dispatches the correct actions', () => {91 const mockStore = reduxMockStore(store);92 return mockStore.dispatch(config.actions.create())93 .catch(() => {94 const dispatchedActions = mockStore.getActions();95 const dispatchedActionTypes = dispatchedActions.map((action) => { return action.type; });96 expect(dispatchedActionTypes).toInclude('users_CREATE_REQUEST');97 expect(dispatchedActionTypes).toInclude('users_CREATE_FAILURE');98 expect(dispatchedActionTypes).toNotInclude('users_CREATE_SUCCESS');99 const createFailureAction = find(dispatchedActions, { type: 'users_CREATE_FAILURE' });100 expect(createFailureAction.payload).toEqual({101 errors: {102 http_status: 422,103 base: 'User is not authenticated',104 },105 });106 });107 });108 });109 });110 describe('#destroy', () => {111 afterEach(() => restoreSpies());112 describe('successful call', () => {113 const destroyFunc = createSpy()114 .andCall(() => Promise.resolve());115 const config = new ReduxConfig({116 destroyFunc,117 entityName: 'users',118 schema: schemas.USERS,119 });120 const mockStore = reduxMockStore({121 ...store,122 data: { [userStub.id]: userStub },123 sortedIds: [userStub.id],124 });125 it('calls the destroyFunc', () => {126 const params = { id: 1 };127 return mockStore.dispatch(config.actions.destroy(params))128 .then(() => {129 expect(destroyFunc).toHaveBeenCalledWith(params);130 });131 });132 it('dispatches the correct actions', () => {133 return mockStore.dispatch(config.actions.destroy())134 .then(() => {135 const dispatchedActions = mockStore.getActions();136 const dispatchedActionTypes = dispatchedActions.map((action) => { return action.type; });137 expect(dispatchedActionTypes).toInclude('users_DESTROY_REQUEST');138 expect(dispatchedActionTypes).toInclude('users_DESTROY_SUCCESS');139 expect(dispatchedActionTypes).toNotInclude('users_DESTROY_FAILURE');140 });141 });142 it('removes the entity from state', () => {143 const promise = config.actions.destroy({ id: userStub.id });144 return mockStore.dispatch(promise)145 .then(() => {146 const dispatchedActions = mockStore.getActions();147 const destroySuccessAction = dispatchedActions.find(action => action.type === 'users_DESTROY_SUCCESS');148 const state = mockStore.getState();149 expect(destroySuccessAction.payload).toEqual({ data: { id: userStub.id } });150 expect(config.reducer(state, destroySuccessAction)).toEqual({ ...store, sortedIds: [] });151 });152 });153 });154 describe('unsuccessful call', () => {155 const destroyFunc = createSpy()156 .andCall(() => Promise.reject(standardError));157 const config = new ReduxConfig({158 destroyFunc,159 entityName: 'users',160 parseServerErrorsFunc,161 schema: schemas.USERS,162 });163 it('calls the destroyFunc', () => {164 const mockStore = reduxMockStore(store);165 const params = { id: 1 };166 return mockStore.dispatch(config.actions.destroy(params))167 .catch(() => {168 expect(destroyFunc).toHaveBeenCalledWith(params);169 });170 });171 it('dispatches the correct actions', () => {172 const mockStore = reduxMockStore(store);173 return mockStore.dispatch(config.actions.destroy())174 .catch(() => {175 const dispatchedActions = mockStore.getActions();176 const dispatchedActionTypes = dispatchedActions.map((action) => { return action.type; });177 expect(dispatchedActionTypes).toInclude('users_DESTROY_REQUEST');178 expect(dispatchedActionTypes).toInclude('users_DESTROY_FAILURE');179 expect(dispatchedActionTypes).toNotInclude('users_DESTROY_SUCCESS');180 const destroyFailureAction = find(dispatchedActions, { type: 'users_DESTROY_FAILURE' });181 expect(destroyFailureAction.payload).toEqual({182 errors: {183 http_status: 422,184 base: 'User is not authenticated',185 },186 });187 });188 });189 });190 });191 describe('#load', () => {192 afterEach(() => restoreSpies());193 describe('successful call', () => {194 const loadFunc = createSpy()195 .andCall(() => Promise.resolve());196 const config = new ReduxConfig({197 entityName: 'users',198 loadFunc,199 schema: schemas.USERS,200 });201 const mockStore = reduxMockStore(store);202 it('calls the loadFunc', () => {203 const params = { id: 1 };204 return mockStore.dispatch(config.actions.load(params))205 .then(() => {206 expect(loadFunc).toHaveBeenCalledWith(params);207 });208 });209 it('dispatches the correct actions', () => {210 return mockStore.dispatch(config.actions.load())211 .then(() => {212 const dispatchedActions = mockStore.getActions();213 const dispatchedActionTypes = dispatchedActions.map((action) => { return action.type; });214 expect(dispatchedActionTypes).toInclude('users_LOAD_REQUEST');215 expect(dispatchedActionTypes).toInclude('users_LOAD_SUCCESS');216 expect(dispatchedActionTypes).toNotInclude('users_LOAD_FAILURE');217 });218 });219 });220 describe('unsuccessful call', () => {221 const loadFunc = createSpy()222 .andCall(() => Promise.reject(standardError));223 const config = new ReduxConfig({224 entityName: 'users',225 loadFunc,226 parseServerErrorsFunc,227 schema: schemas.USERS,228 });229 it('calls the loadFunc', () => {230 const mockStore = reduxMockStore(store);231 const params = { id: 1 };232 return mockStore.dispatch(config.actions.load(params))233 .catch(() => {234 expect(loadFunc).toHaveBeenCalledWith(params);235 });236 });237 it('dispatches the correct actions', () => {238 const mockStore = reduxMockStore(store);239 return mockStore.dispatch(config.actions.load())240 .catch(() => {241 const dispatchedActions = mockStore.getActions();242 const dispatchedActionTypes = dispatchedActions.map((action) => { return action.type; });243 expect(dispatchedActionTypes).toInclude('users_LOAD_REQUEST');244 expect(dispatchedActionTypes).toInclude('users_LOAD_FAILURE');245 expect(dispatchedActionTypes).toNotInclude('users_LOAD_SUCCESS');246 const loadFailureAction = find(dispatchedActions, { type: 'users_LOAD_FAILURE' });247 expect(loadFailureAction.payload).toEqual({248 errors: {249 http_status: 422,250 base: 'User is not authenticated',251 },252 });253 });254 });255 });256 });257 describe('#loadAll', () => {258 afterEach(() => restoreSpies());259 describe('successful call', () => {260 const loadAllFunc = createSpy()261 .andCall(() => Promise.resolve());262 const config = new ReduxConfig({263 entityName: 'users',264 loadAllFunc,265 schema: schemas.USERS,266 });267 const mockStore = reduxMockStore(store);268 it('calls the loadAllFunc', () => {269 const params = { id: 1 };270 return mockStore.dispatch(config.actions.loadAll(params))271 .then(() => {272 expect(loadAllFunc).toHaveBeenCalledWith(params);273 });274 });275 it('dispatches the correct actions', () => {276 return mockStore.dispatch(config.actions.loadAll())277 .then(() => {278 const dispatchedActions = mockStore.getActions();279 const dispatchedActionTypes = dispatchedActions.map((action) => { return action.type; });280 expect(dispatchedActionTypes).toInclude('users_LOAD_REQUEST');281 expect(dispatchedActionTypes).toInclude('users_LOAD_ALL_SUCCESS');282 expect(dispatchedActionTypes).toNotInclude('users_LOAD_FAILURE');283 });284 });285 });286 describe('unsuccessful call', () => {287 const loadAllFunc = createSpy()288 .andCall(() => Promise.reject(standardError));289 const config = new ReduxConfig({290 entityName: 'users',291 loadAllFunc,292 parseServerErrorsFunc,293 schema: schemas.USERS,294 });295 it('calls the loadAllFunc', () => {296 const mockStore = reduxMockStore(store);297 const params = { id: 1 };298 return mockStore.dispatch(config.actions.loadAll(params))299 .catch(() => {300 expect(loadAllFunc).toHaveBeenCalledWith(params);301 });302 });303 it('dispatches the correct actions', () => {304 const mockStore = reduxMockStore(store);305 return mockStore.dispatch(config.actions.loadAll())306 .catch(() => {307 const dispatchedActions = mockStore.getActions();308 const dispatchedActionTypes = dispatchedActions.map((action) => { return action.type; });309 expect(dispatchedActionTypes).toInclude('users_LOAD_REQUEST');310 expect(dispatchedActionTypes).toInclude('users_LOAD_FAILURE');311 expect(dispatchedActionTypes).toNotInclude('users_LOAD_ALL_SUCCESS');312 const loadAllFailureAction = find(dispatchedActions, { type: 'users_LOAD_FAILURE' });313 expect(loadAllFailureAction.payload).toEqual({314 errors: {315 http_status: 422,316 base: 'User is not authenticated',317 },318 });319 });320 });321 });322 });323 describe('#update', () => {324 afterEach(() => restoreSpies());325 describe('successful call', () => {326 const updateFunc = createSpy()327 .andCall(() => Promise.resolve());328 const config = new ReduxConfig({329 entityName: 'users',330 schema: schemas.USERS,331 updateFunc,332 });333 const mockStore = reduxMockStore(store);334 it('calls the updateFunc', () => {335 const params = { id: 1 };336 return mockStore.dispatch(config.actions.update(params))337 .then(() => {338 expect(updateFunc).toHaveBeenCalledWith(params);339 });340 });341 it('dispatches the correct actions', () => {342 return mockStore.dispatch(config.actions.update())343 .then(() => {344 const dispatchedActions = mockStore.getActions();345 const dispatchedActionTypes = dispatchedActions.map((action) => { return action.type; });346 expect(dispatchedActionTypes).toInclude('users_UPDATE_REQUEST');347 expect(dispatchedActionTypes).toInclude('users_UPDATE_SUCCESS');348 expect(dispatchedActionTypes).toNotInclude('users_UPDATE_FAILURE');349 });350 });351 });352 describe('unsuccessful call', () => {353 const updateFunc = createSpy()354 .andCall(() => Promise.reject(standardError));355 const config = new ReduxConfig({356 entityName: 'users',357 parseServerErrorsFunc,358 schema: schemas.USERS,359 updateFunc,360 });361 it('calls the updateFunc', () => {362 const mockStore = reduxMockStore(store);363 const params = { id: 1 };364 return mockStore.dispatch(config.actions.update(params))365 .catch(() => {366 expect(updateFunc).toHaveBeenCalledWith(params);367 });368 });369 it('dispatches the correct actions', () => {370 const mockStore = reduxMockStore(store);371 return mockStore.dispatch(config.actions.update())372 .catch(() => {373 const dispatchedActions = mockStore.getActions();374 const dispatchedActionTypes = dispatchedActions.map((action) => { return action.type; });375 expect(dispatchedActionTypes).toInclude('users_UPDATE_REQUEST');376 expect(dispatchedActionTypes).toInclude('users_UPDATE_FAILURE');377 expect(dispatchedActionTypes).toNotInclude('users_UPDATE_SUCCESS');378 const updateFailureAction = find(dispatchedActions, { type: 'users_UPDATE_FAILURE' });379 expect(updateFailureAction.payload).toEqual({380 errors: {381 http_status: 422,382 base: 'User is not authenticated',383 },384 });385 });386 });387 });388 });389 describe('unsuccessful call with no parseServerErrorsFunc passed to config block', () => {390 const updateFunc = () => Promise.reject(standardError);391 const config = new ReduxConfig({392 entityName: 'users',393 schema: schemas.USERS,394 updateFunc,395 });396 it('returns the unformatted result as the errors response', () => {397 const mockStore = reduxMockStore(store);398 return mockStore.dispatch(config.actions.update())399 .catch((response) => {400 const dispatchedActions = mockStore.getActions();401 const updateFailureAction = find(dispatchedActions, { type: 'users_UPDATE_FAILURE' });402 expect(response).toEqual(standardError);403 expect(updateFailureAction.payload).toEqual({ errors: standardError });404 });405 });406 });...
mr_widget_pipeline_container_spec.js
Source:mr_widget_pipeline_container_spec.js
1import { mount } from '@vue/test-utils';2import MockAdapter from 'axios-mock-adapter';3import { extendedWrapper } from 'helpers/vue_test_utils_helper';4import axios from '~/lib/utils/axios_utils';5import ArtifactsApp from '~/vue_merge_request_widget/components/artifacts_list_app.vue';6import DeploymentList from '~/vue_merge_request_widget/components/deployment/deployment_list.vue';7import MrWidgetPipeline from '~/vue_merge_request_widget/components/mr_widget_pipeline.vue';8import MrWidgetPipelineContainer from '~/vue_merge_request_widget/components/mr_widget_pipeline_container.vue';9import { mockStore } from '../mock_data';10describe('MrWidgetPipelineContainer', () => {11 let wrapper;12 let mock;13 const factory = (props = {}) => {14 wrapper = extendedWrapper(15 mount(MrWidgetPipelineContainer, {16 propsData: {17 mr: { ...mockStore },18 ...props,19 },20 }),21 );22 };23 beforeEach(() => {24 mock = new MockAdapter(axios);25 mock.onGet().reply(200, {});26 });27 afterEach(() => {28 wrapper.destroy();29 });30 const findDeploymentList = () => wrapper.findComponent(DeploymentList);31 const findCIErrorMessage = () => wrapper.findByTestId('ci-error-message');32 describe('when pre merge', () => {33 beforeEach(() => {34 factory();35 });36 it('renders pipeline', () => {37 expect(wrapper.find(MrWidgetPipeline).exists()).toBe(true);38 expect(wrapper.find(MrWidgetPipeline).props()).toMatchObject({39 pipeline: mockStore.pipeline,40 pipelineCoverageDelta: mockStore.pipelineCoverageDelta,41 ciStatus: mockStore.ciStatus,42 hasCi: mockStore.hasCI,43 sourceBranch: mockStore.sourceBranch,44 sourceBranchLink: mockStore.sourceBranchLink,45 });46 });47 it('renders deployments', () => {48 const expectedProps = mockStore.deployments.map((dep) =>49 expect.objectContaining({50 deployment: dep,51 showMetrics: false,52 }),53 );54 const deployments = wrapper.findAll('.mr-widget-extension .js-pre-deployment');55 expect(findDeploymentList().exists()).toBe(true);56 expect(findDeploymentList().props('deployments')).toBe(mockStore.deployments);57 expect(deployments.wrappers.map((x) => x.props())).toEqual(expectedProps);58 });59 });60 describe('when post merge', () => {61 beforeEach(() => {62 factory({63 isPostMerge: true,64 mr: {65 ...mockStore,66 pipeline: {},67 ciStatus: undefined,68 },69 });70 });71 it('renders pipeline', () => {72 expect(wrapper.find(MrWidgetPipeline).exists()).toBe(true);73 expect(findCIErrorMessage().exists()).toBe(false);74 expect(wrapper.find(MrWidgetPipeline).props()).toMatchObject({75 pipeline: mockStore.mergePipeline,76 pipelineCoverageDelta: mockStore.pipelineCoverageDelta,77 ciStatus: mockStore.mergePipeline.details.status.text,78 hasCi: mockStore.hasCI,79 sourceBranch: mockStore.targetBranch,80 sourceBranchLink: mockStore.targetBranch,81 });82 });83 it('sanitizes the targetBranch', () => {84 factory({85 isPostMerge: true,86 mr: {87 ...mockStore,88 targetBranch: 'Foo<script>alert("XSS")</script>',89 },90 });91 expect(wrapper.find(MrWidgetPipeline).props().sourceBranchLink).toBe('Foo');92 });93 it('renders deployments', () => {94 const expectedProps = mockStore.postMergeDeployments.map((dep) =>95 expect.objectContaining({96 deployment: dep,97 showMetrics: true,98 }),99 );100 const deployments = wrapper.findAll('.mr-widget-extension .js-post-deployment');101 expect(findDeploymentList().exists()).toBe(true);102 expect(findDeploymentList().props('deployments')).toBe(mockStore.postMergeDeployments);103 expect(deployments.wrappers.map((x) => x.props())).toEqual(expectedProps);104 });105 });106 describe('with artifacts path', () => {107 it('renders the artifacts app', () => {108 factory();109 expect(wrapper.find(ArtifactsApp).isVisible()).toBe(true);110 });111 });...
user.js
Source:user.js
1const UserAPI = require('../user');2const mockStore = {3 users: {4 findOrCreate: jest.fn(),5 findAll: jest.fn(),6 },7 trips: {8 findOrCreate: jest.fn(),9 destroy: jest.fn(),10 findAll: jest.fn(),11 },12};13module.exports.mockStore = mockStore;14const ds = new UserAPI({ store: mockStore });15ds.initialize({ context: { user: { id: 1, email: 'a@a.a' } } });16describe('[UserAPI.findOrCreateUser]', () => {17 it('returns null for invalid emails', async () => {18 const res = await ds.findOrCreateUser({ email: 'boo!' });19 expect(res).toEqual(null);20 });21 it('looks up/creates user in store', async () => {22 mockStore.users.findOrCreate.mockReturnValueOnce([{ id: 1 }]);23 // check the result of the fn24 const res = await ds.findOrCreateUser({ email: 'a@a.a' });25 expect(res).toEqual({ id: 1 });26 // make sure store is called properly27 expect(mockStore.users.findOrCreate).toBeCalledWith({28 where: { email: 'a@a.a' },29 });30 });31 it('returns null if no user found/created', async () => {32 // store lookup is not mocked to return anything, so this33 // simulates a failed lookup34 const res = await ds.findOrCreateUser({ email: 'a@a.a' });35 expect(res).toEqual(null);36 });37});38describe('[UserAPI.bookTrip]', () => {39 it('calls store creator and returns result', async () => {40 mockStore.trips.findOrCreate.mockReturnValueOnce([{ get: () => 'heya' }]);41 // check the result of the fn42 const res = await ds.bookTrip({ launchId: 1 });43 expect(res).toBeTruthy();44 // make sure store is called properly45 expect(mockStore.trips.findOrCreate).toBeCalledWith({46 where: { launchId: 1, userId: 1 },47 });48 });49});50describe('[UserAPI.bookTrips]', () => {51 it('returns multiple lookups from bookTrip', async () => {52 mockStore.trips.findOrCreate.mockReturnValueOnce([{ get: () => 'heya' }]);53 mockStore.trips.findOrCreate.mockReturnValueOnce([{ get: () => 'okay' }]);54 const res = await ds.bookTrips({ launchIds: [1, 2] });55 expect(res).toEqual(['heya', 'okay']);56 });57});58describe('[UserAPI.cancelTrip]', () => {59 it('calls store destroy and returns result', async () => {60 const args = { userId: 1, launchId: 1 };61 mockStore.trips.destroy.mockReturnValueOnce('heya');62 // check the result of the fn63 const res = await ds.cancelTrip(args);64 expect(res).toEqual(true);65 // make sure store is called properly66 expect(mockStore.trips.destroy).toBeCalledWith({ where: args });67 });68});69describe('[UserAPI.getLaunchIdsByUser]', () => {70 it('looks up launches by user', async () => {71 const args = { userId: 1 };72 const launches = [73 { dataValues: { launchId: 1 } },74 { dataValues: { launchId: 2 } },75 ];76 mockStore.trips.findAll.mockReturnValueOnce(launches);77 // check the result of the fn78 const res = await ds.getLaunchIdsByUser(args);79 expect(res).toEqual([1, 2]);80 // make sure store is called properly81 expect(mockStore.trips.findAll).toBeCalledWith({ where: args });82 });83 it('returns empty array if nothing found', async () => {84 const args = { userId: 1 };85 // store lookup is not mocked to return anything, so this86 // simulates a failed lookup87 // check the result of the fn88 const res = await ds.getLaunchIdsByUser(args);89 expect(res).toEqual([]);90 });...
Using AI Code Generation
1import configureMockStore from 'redux-mock-store';2import thunk from 'redux-thunk';3import * as actions from './actions';4import * as types from './actionTypes';5import fetchMock from 'fetch-mock';6const middlewares = [thunk];7const mockStore = configureMockStore(middlewares);8describe('async actions', () => {9 afterEach(() => {10 fetchMock.restore();11 });12 it('creates FETCH_POSTS_SUCCESS when fetching posts has been done', () => {13 body: { posts: ['do something'] },14 headers: { 'content-type': 'application/json' }15 });16 { type: types.FETCH_POSTS_BEGIN },17 { type: types.FETCH_POSTS_SUCCESS, payload: { posts: ['do something'] } }18 ];19 const store = mockStore({ posts: [] });20 return store.dispatch(actions.fetchPosts()).then(() => {21 expect(store.getActions()).toEqual(expectedActions);22 });23 });24});
Using AI Code Generation
1import React from 'react';2import { shallow } from 'enzyme';3import configureStore from 'redux-mock-store';4import { Provider } from 'react-redux';5import App from './App';6const mockStore = configureStore([]);7describe('App', () => {8 let wrapper, store;9 beforeEach(() => {10 store = mockStore({11 posts: {12 }13 });14 wrapper = shallow(15 <Provider store={store}>16 );17 });18 it('should render the component', () => {19 expect(wrapper).toMatchSnapshot();20 });21});22import React, { Component } from 'react';23import { connect } from 'react-redux';24import { fetchPosts } from './actions/postsActions';25class App extends Component {26 componentDidMount() {27 this.props.fetchPosts();28 }29 render() {30 return (31 );32 }33}34const mapStateToProps = state => ({35});36export default connect(37 { fetchPosts }38)(App);39import { FETCH_POSTS, NEW_POST } from './types';40export const fetchPosts = () => dispatch => {41 .then(res => res.json())42 .then(posts =>43 dispatch({44 })45 );46};47export const createPost = postData => dispatch => {48 headers: {49 },50 body: JSON.stringify(postData)51 })52 .then(res => res.json())53 .then(post =>54 dispatch({55 })56 );57};58import { FETCH_POSTS, NEW_POST } from '../actions/types';59const initialState = {60 item: {},61};62export default function(state = initialState, action) {63 switch (action.type) {
Using AI Code Generation
1const mockStore = configureMockStore([thunk]);2jest.mock("../../services/BestBuyApi");3const store = mockStore({});4const mockResponse = {5 {6 },7 {8 }9};10describe("test actions", () => {11 beforeEach(() => {12 store.clearActions();13 });14 it("should create an action to add products", () => {15 {16 },17 {18 }19 ];20 const expectedAction = {21 };22 expect(actions.addProducts(products)).toEqual(expectedAction);23 });24 it("should create an action to add a product", () => {25 const product = {26 };27 const expectedAction = {28 };29 expect(actions.addProduct(product)).toEqual(expectedAction);30 });31 it("should create an
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!