Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 50f9e49

Browse files
author
Kumiko
authored
fix: standardize mock store setup in tests (#2075)
1 parent 739863f commit 50f9e49

32 files changed

+173
-144
lines changed

src/__tests__/HospitalRun.test.tsx

+10-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import React from 'react'
66
import { act } from 'react-dom/test-utils'
77
import { Provider } from 'react-redux'
88
import { MemoryRouter } from 'react-router-dom'
9-
import configureMockStore from 'redux-mock-store'
9+
import createMockStore from 'redux-mock-store'
1010
import thunk from 'redux-thunk'
1111

1212
import { addBreadcrumbs } from '../breadcrumbs/breadcrumbs-slice'
@@ -17,8 +17,9 @@ import Incidents from '../incidents/Incidents'
1717
import ViewLabs from '../labs/ViewLabs'
1818
import Permissions from '../model/Permissions'
1919
import Appointments from '../scheduling/appointments/Appointments'
20+
import { RootState } from '../store'
2021

21-
const mockStore = configureMockStore([thunk])
22+
const mockStore = createMockStore<RootState, any>([thunk])
2223

2324
describe('HospitalRun', () => {
2425
describe('routing', () => {
@@ -31,7 +32,7 @@ describe('HospitalRun', () => {
3132
breadcrumbs: { breadcrumbs: [] },
3233
components: { sidebarCollapsed: false },
3334
incidents: { incidents: [] },
34-
})
35+
} as any)
3536

3637
const wrapper = mount(
3738
<Provider store={store}>
@@ -63,7 +64,7 @@ describe('HospitalRun', () => {
6364
user: { permissions: [] },
6465
breadcrumbs: { breadcrumbs: [] },
6566
components: { sidebarCollapsed: false },
66-
})}
67+
} as any)}
6768
>
6869
<MemoryRouter initialEntries={['/appointments']}>
6970
<HospitalRun />
@@ -84,7 +85,7 @@ describe('HospitalRun', () => {
8485
labs: { labs: [] },
8586
breadcrumbs: { breadcrumbs: [] },
8687
components: { sidebarCollapsed: false },
87-
})
88+
} as any)
8889

8990
let wrapper: any
9091
await act(async () => {
@@ -108,7 +109,7 @@ describe('HospitalRun', () => {
108109
user: { permissions: [] },
109110
breadcrumbs: { breadcrumbs: [] },
110111
components: { sidebarCollapsed: false },
111-
})
112+
} as any)
112113

113114
const wrapper = mount(
114115
<Provider store={store}>
@@ -131,7 +132,7 @@ describe('HospitalRun', () => {
131132
breadcrumbs: { breadcrumbs: [] },
132133
components: { sidebarCollapsed: false },
133134
incidents: { incidents: [] },
134-
})
135+
} as any)
135136

136137
let wrapper: any
137138
await act(async () => {
@@ -155,7 +156,7 @@ describe('HospitalRun', () => {
155156
user: { permissions: [] },
156157
breadcrumbs: { breadcrumbs: [] },
157158
components: { sidebarCollapsed: false },
158-
})
159+
} as any)
159160

160161
const wrapper = mount(
161162
<Provider store={store}>
@@ -180,7 +181,7 @@ describe('HospitalRun', () => {
180181
user: { permissions: [Permissions.WritePatients] },
181182
breadcrumbs: { breadcrumbs: [] },
182183
components: { sidebarCollapsed: false },
183-
})}
184+
} as any)}
184185
>
185186
<MemoryRouter initialEntries={['/']}>
186187
<HospitalRun />

src/__tests__/breadcrumbs/Breadcrumbs.test.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import '../../__mocks__/matchMediaMock'
2-
32
import {
43
Breadcrumb as HRBreadcrumb,
54
BreadcrumbItem as HRBreadcrumbItem,
@@ -9,19 +8,21 @@ import { createMemoryHistory } from 'history'
98
import React from 'react'
109
import { Provider } from 'react-redux'
1110
import { Router } from 'react-router-dom'
12-
import configureMockStore from 'redux-mock-store'
11+
import createMockStore from 'redux-mock-store'
12+
import thunk from 'redux-thunk'
1313

1414
import Breadcrumbs from '../../breadcrumbs/Breadcrumbs'
1515
import Breadcrumb from '../../model/Breadcrumb'
16+
import { RootState } from '../../store'
1617

17-
const mockStore = configureMockStore()
18+
const mockStore = createMockStore<RootState, any>([thunk])
1819

1920
describe('Breadcrumbs', () => {
2021
const setup = (breadcrumbs: Breadcrumb[]) => {
2122
const history = createMemoryHistory()
2223
const store = mockStore({
2324
breadcrumbs: { breadcrumbs },
24-
})
25+
} as any)
2526

2627
const wrapper = mount(
2728
<Provider store={store}>

src/__tests__/breadcrumbs/useAddBreadcrumbs.test.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { renderHook } from '@testing-library/react-hooks'
22
import React from 'react'
33
import { Provider } from 'react-redux'
4-
import configureMockStore from 'redux-mock-store'
4+
import createMockStore from 'redux-mock-store'
5+
import thunk from 'redux-thunk'
56

67
import * as breadcrumbsSlice from '../../breadcrumbs/breadcrumbs-slice'
78
import useAddBreadcrumbs from '../../breadcrumbs/useAddBreadcrumbs'
9+
import { RootState } from '../../store'
810

9-
const store = configureMockStore()
11+
const mockStore = createMockStore<RootState, any>([thunk])
1012

1113
describe('useAddBreadcrumbs', () => {
1214
beforeEach(() => jest.clearAllMocks())
1315

1416
it('should call addBreadcrumbs with the correct data', () => {
15-
const wrapper = ({ children }: any) => <Provider store={store({})}>{children}</Provider>
17+
const wrapper = ({ children }: any) => <Provider store={mockStore({})}>{children}</Provider>
1618

1719
jest.spyOn(breadcrumbsSlice, 'addBreadcrumbs')
1820
const breadcrumbs = [
@@ -28,7 +30,7 @@ describe('useAddBreadcrumbs', () => {
2830
})
2931

3032
it('should call addBreadcrumbs with an additional dashboard breadcrumb', () => {
31-
const wrapper = ({ children }: any) => <Provider store={store({})}>{children}</Provider>
33+
const wrapper = ({ children }: any) => <Provider store={mockStore({})}>{children}</Provider>
3234

3335
jest.spyOn(breadcrumbsSlice, 'addBreadcrumbs')
3436
const breadcrumbs = [
@@ -47,7 +49,7 @@ describe('useAddBreadcrumbs', () => {
4749
})
4850

4951
it('should call removeBreadcrumbs with the correct data after unmount', () => {
50-
const wrapper = ({ children }: any) => <Provider store={store({})}>{children}</Provider>
52+
const wrapper = ({ children }: any) => <Provider store={mockStore({})}>{children}</Provider>
5153

5254
jest.spyOn(breadcrumbsSlice, 'addBreadcrumbs')
5355
jest.spyOn(breadcrumbsSlice, 'removeBreadcrumbs')

src/__tests__/components/Sidebar.test.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ import { createMemoryHistory } from 'history'
77
import React from 'react'
88
import { Provider } from 'react-redux'
99
import { Router } from 'react-router-dom'
10-
import configureMockStore from 'redux-mock-store'
10+
import createMockStore from 'redux-mock-store'
1111
import thunk from 'redux-thunk'
1212

1313
import Sidebar from '../../components/Sidebar'
14+
import { RootState } from '../../store'
1415

15-
const mockStore = configureMockStore([thunk])
16+
const mockStore = createMockStore<RootState, any>([thunk])
1617

1718
describe('Sidebar', () => {
1819
let history = createMemoryHistory()
1920
const store = mockStore({
2021
components: { sidebarCollapsed: false },
21-
})
22+
} as any)
2223
const setup = (location: string) => {
2324
history = createMemoryHistory()
2425
history.push(location)

src/__tests__/incidents/Incidents.test.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { mount } from 'enzyme'
55
import React from 'react'
66
import { Provider } from 'react-redux'
77
import { MemoryRouter } from 'react-router-dom'
8-
import configureMockStore from 'redux-mock-store'
8+
import createMockStore from 'redux-mock-store'
99
import thunk from 'redux-thunk'
1010

1111
import IncidentRepository from '../../clients/db/IncidentRepository'
@@ -14,8 +14,9 @@ import ReportIncident from '../../incidents/report/ReportIncident'
1414
import ViewIncident from '../../incidents/view/ViewIncident'
1515
import Incident from '../../model/Incident'
1616
import Permissions from '../../model/Permissions'
17+
import { RootState } from '../../store'
1718

18-
const mockStore = configureMockStore([thunk])
19+
const mockStore = createMockStore<RootState, any>([thunk])
1920

2021
describe('Incidents', () => {
2122
describe('routing', () => {
@@ -34,7 +35,7 @@ describe('Incidents', () => {
3435
incident: {
3536
incident: expectedIncident,
3637
},
37-
})
38+
} as any)
3839

3940
const wrapper = mount(
4041
<Provider store={store}>
@@ -53,7 +54,7 @@ describe('Incidents', () => {
5354
user: { permissions: [] },
5455
breadcrumbs: { breadcrumbs: [] },
5556
components: { sidebarCollapsed: false },
56-
})
57+
} as any)
5758

5859
const wrapper = mount(
5960
<Provider store={store}>
@@ -82,7 +83,7 @@ describe('Incidents', () => {
8283
reportedOn: new Date().toISOString(),
8384
},
8485
},
85-
})
86+
} as any)
8687

8788
let wrapper: any
8889

@@ -105,7 +106,7 @@ describe('Incidents', () => {
105106
user: { permissions: [] },
106107
breadcrumbs: { breadcrumbs: [] },
107108
components: { sidebarCollapsed: false },
108-
})
109+
} as any)
109110

110111
const wrapper = await mount(
111112
<Provider store={store}>

src/__tests__/incidents/list/ViewIncidents.test.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import Incident from '../../../model/Incident'
1616
import Permissions from '../../../model/Permissions'
1717
import * as ButtonBarProvider from '../../../page-header/ButtonBarProvider'
1818
import * as titleUtil from '../../../page-header/useTitle'
19+
import { RootState } from '../../../store'
1920

20-
const mockStore = createMockStore([thunk])
21+
const mockStore = createMockStore<RootState, any>([thunk])
2122

2223
describe('View Incidents', () => {
2324
let history: any
@@ -52,7 +53,7 @@ describe('View Incidents', () => {
5253
incidents: {
5354
incidents: expectedIncidents,
5455
},
55-
})
56+
} as any)
5657

5758
let wrapper: any
5859
await act(async () => {

src/__tests__/incidents/report/ReportIncident.test.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import ReportIncident from '../../../incidents/report/ReportIncident'
1616
import Permissions from '../../../model/Permissions'
1717
import * as ButtonBarProvider from '../../../page-header/ButtonBarProvider'
1818
import * as titleUtil from '../../../page-header/useTitle'
19+
import { RootState } from '../../../store'
1920

20-
const mockStore = createMockStore([thunk])
21+
const mockStore = createMockStore<RootState, any>([thunk])
2122

2223
describe('Report Incident', () => {
2324
let history: any
@@ -43,7 +44,7 @@ describe('Report Incident', () => {
4344
incident: {
4445
error,
4546
},
46-
})
47+
} as any)
4748

4849
let wrapper: any
4950
await act(async () => {

src/__tests__/incidents/view/ViewIncident.test.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import Incident from '../../../model/Incident'
1616
import Permissions from '../../../model/Permissions'
1717
import * as ButtonBarProvider from '../../../page-header/ButtonBarProvider'
1818
import * as titleUtil from '../../../page-header/useTitle'
19+
import { RootState } from '../../../store'
1920

20-
const mockStore = createMockStore([thunk])
21+
const mockStore = createMockStore<RootState, any>([thunk])
2122

2223
describe('View Incident', () => {
2324
const expectedDate = new Date(2020, 5, 1, 19, 48)
@@ -52,7 +53,7 @@ describe('View Incident', () => {
5253
incident: {
5354
incident: expectedIncident,
5455
},
55-
})
56+
} as any)
5657

5758
let wrapper: any
5859
await act(async () => {

src/__tests__/labs/Labs.test.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { mount } from 'enzyme'
55
import React from 'react'
66
import { Provider } from 'react-redux'
77
import { MemoryRouter } from 'react-router-dom'
8-
import configureMockStore from 'redux-mock-store'
8+
import createMockStore from 'redux-mock-store'
99
import thunk from 'redux-thunk'
1010

1111
import LabRepository from '../../clients/db/LabRepository'
@@ -16,8 +16,9 @@ import ViewLab from '../../labs/ViewLab'
1616
import Lab from '../../model/Lab'
1717
import Patient from '../../model/Patient'
1818
import Permissions from '../../model/Permissions'
19+
import { RootState } from '../../store'
1920

20-
const mockStore = configureMockStore([thunk])
21+
const mockStore = createMockStore<RootState, any>([thunk])
2122

2223
describe('Labs', () => {
2324
jest.spyOn(LabRepository, 'findAll').mockResolvedValue([])
@@ -41,7 +42,7 @@ describe('Labs', () => {
4142
patient: { id: 'patientId', fullName: 'some name' },
4243
error: {},
4344
},
44-
})
45+
} as any)
4546

4647
const wrapper = mount(
4748
<Provider store={store}>
@@ -60,7 +61,7 @@ describe('Labs', () => {
6061
user: { permissions: [] },
6162
breadcrumbs: { breadcrumbs: [] },
6263
components: { sidebarCollapsed: false },
63-
})
64+
} as any)
6465

6566
const wrapper = mount(
6667
<Provider store={store}>
@@ -90,7 +91,7 @@ describe('Labs', () => {
9091
patient: { id: 'patientId', fullName: 'some name' },
9192
error: {},
9293
},
93-
})
94+
} as any)
9495

9596
let wrapper: any
9697

@@ -113,7 +114,7 @@ describe('Labs', () => {
113114
user: { permissions: [] },
114115
breadcrumbs: { breadcrumbs: [] },
115116
components: { sidebarCollapsed: false },
116-
})
117+
} as any)
117118

118119
const wrapper = await mount(
119120
<Provider store={store}>

src/__tests__/labs/ViewLab.test.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import Patient from '../../model/Patient'
2020
import Permissions from '../../model/Permissions'
2121
import * as ButtonBarProvider from '../../page-header/ButtonBarProvider'
2222
import * as titleUtil from '../../page-header/useTitle'
23+
import { RootState } from '../../store'
2324

24-
const mockStore = createMockStore([thunk])
25+
const mockStore = createMockStore<RootState, any>([thunk])
2526

2627
describe('View Labs', () => {
2728
let history: any
@@ -63,7 +64,7 @@ describe('View Labs', () => {
6364
error,
6465
status: Object.keys(error).length > 0 ? 'error' : 'completed',
6566
},
66-
})
67+
} as any)
6768

6869
let wrapper: any
6970
await act(async () => {

0 commit comments

Comments
 (0)