Skip to content

Commit d133bb6

Browse files
committed
Migrate from Jest to Vitest
1 parent 40c1838 commit d133bb6

11 files changed

+114
-122
lines changed

jest.config.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

test/components/Provider.spec.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('React', () => {
5151
it('should not enforce a single child', () => {
5252
const store = createStore(() => ({}))
5353

54-
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
54+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
5555

5656
expect(() =>
5757
rtl.render(
@@ -79,7 +79,7 @@ describe('React', () => {
7979
it('should add the store to context', () => {
8080
const store = createStore(createExampleTextReducer())
8181

82-
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
82+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
8383
const tester = rtl.render(
8484
<Provider store={store}>
8585
<Child />
@@ -170,7 +170,7 @@ describe('React', () => {
170170
action.type === 'INC' ? state + 1 : state
171171

172172
const innerStore = createStore(reducer)
173-
const innerMapStateToProps = jest.fn<TStateProps, [number]>((state) => ({
173+
const innerMapStateToProps = vi.fn<TStateProps, [number]>((state) => ({
174174
count: state,
175175
}))
176176
class Inner extends Component<TStateProps> {
@@ -315,7 +315,7 @@ describe('React', () => {
315315
if (!React.StrictMode) {
316316
return
317317
}
318-
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
318+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
319319
const store = createStore(() => ({}))
320320

321321
rtl.render(
@@ -334,7 +334,7 @@ describe('React', () => {
334334
const subscribe = store.subscribe
335335

336336
// Keep track of unsubscribe by wrapping subscribe()
337-
const spy = jest.fn(() => ({}))
337+
const spy = vi.fn(() => ({}))
338338
store.subscribe = (listener) => {
339339
const unsubscribe = subscribe(listener)
340340
return () => {

test/components/connect.spec.tsx

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import * as rtl from '@testing-library/react'
55
import type { Dispatch, ElementType, MouseEvent, ReactNode } from 'react'
66
import React, { Component } from 'react'
77
import type {
8-
Action,
9-
AnyAction,
10-
MiddlewareAPI,
11-
Dispatch as ReduxDispatch,
12-
Store,
13-
UnknownAction,
8+
Action,
9+
AnyAction,
10+
MiddlewareAPI,
11+
Dispatch as ReduxDispatch,
12+
Store,
13+
UnknownAction,
1414
} from 'redux'
1515
import { applyMiddleware, createStore } from 'redux'
1616
import type { ReactReduxContextValue } from '../../src/index'
@@ -199,7 +199,7 @@ describe('React', () => {
199199
string: state,
200200
}))(Container)
201201

202-
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
202+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
203203

204204
const tester = rtl.render(
205205
<ProviderMock store={store}>
@@ -243,7 +243,7 @@ describe('React', () => {
243243
string: state,
244244
}))(Container)
245245

246-
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
246+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
247247
const tester = rtl.render(
248248
<ProviderMock store={store as unknown as Store}>
249249
<ConnectedContainer />
@@ -261,7 +261,7 @@ describe('React', () => {
261261
})
262262

263263
it('should throw an error if the store is not in the props or context', () => {
264-
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
264+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
265265

266266
class Container extends Component {
267267
render() {
@@ -643,7 +643,7 @@ describe('React', () => {
643643
}
644644
class AwesomeMap {}
645645

646-
let spy = jest.spyOn(console, 'error').mockImplementation(() => {})
646+
let spy = vi.spyOn(console, 'error').mockImplementation(() => {})
647647
rtl.render(
648648
<ProviderMock store={store}>
649649
{makeContainer(
@@ -660,7 +660,7 @@ describe('React', () => {
660660
spy.mockRestore()
661661
rtl.cleanup()
662662

663-
spy = jest.spyOn(console, 'error').mockImplementation(() => {})
663+
spy = vi.spyOn(console, 'error').mockImplementation(() => {})
664664
rtl.render(
665665
<ProviderMock store={store}>
666666
{makeContainer(
@@ -677,7 +677,7 @@ describe('React', () => {
677677
spy.mockRestore()
678678
rtl.cleanup()
679679

680-
spy = jest.spyOn(console, 'error').mockImplementation(() => {})
680+
spy = vi.spyOn(console, 'error').mockImplementation(() => {})
681681
rtl.render(
682682
<ProviderMock store={store}>
683683
{makeContainer(
@@ -694,7 +694,7 @@ describe('React', () => {
694694
spy.mockRestore()
695695
rtl.cleanup()
696696

697-
spy = jest.spyOn(console, 'error').mockImplementation(() => {})
697+
spy = vi.spyOn(console, 'error').mockImplementation(() => {})
698698
rtl.render(
699699
<ProviderMock store={store}>
700700
{makeContainer(
@@ -711,7 +711,7 @@ describe('React', () => {
711711
spy.mockRestore()
712712
rtl.cleanup()
713713

714-
spy = jest.spyOn(console, 'error').mockImplementation(() => {})
714+
spy = vi.spyOn(console, 'error').mockImplementation(() => {})
715715
rtl.render(
716716
<ProviderMock store={store}>
717717
{makeContainer(
@@ -728,7 +728,7 @@ describe('React', () => {
728728
spy.mockRestore()
729729
rtl.cleanup()
730730

731-
spy = jest.spyOn(console, 'error').mockImplementation(() => {})
731+
spy = vi.spyOn(console, 'error').mockImplementation(() => {})
732732
rtl.render(
733733
<ProviderMock store={store}>
734734
{makeContainer(
@@ -745,7 +745,7 @@ describe('React', () => {
745745
spy.mockRestore()
746746
rtl.cleanup()
747747

748-
spy = jest.spyOn(console, 'error').mockImplementation(() => {})
748+
spy = vi.spyOn(console, 'error').mockImplementation(() => {})
749749
rtl.render(
750750
<ProviderMock store={store}>
751751
{makeContainer(
@@ -762,7 +762,7 @@ describe('React', () => {
762762
spy.mockRestore()
763763
rtl.cleanup()
764764

765-
spy = jest.spyOn(console, 'error').mockImplementation(() => {})
765+
spy = vi.spyOn(console, 'error').mockImplementation(() => {})
766766
rtl.render(
767767
<ProviderMock store={store}>
768768
{makeContainer(
@@ -779,7 +779,7 @@ describe('React', () => {
779779
spy.mockRestore()
780780
rtl.cleanup()
781781

782-
spy = jest.spyOn(console, 'error').mockImplementation(() => {})
782+
spy = vi.spyOn(console, 'error').mockImplementation(() => {})
783783
rtl.render(
784784
<ProviderMock store={store}>
785785
{makeContainer(
@@ -1297,7 +1297,7 @@ describe('React', () => {
12971297
</ProviderMock>,
12981298
)
12991299

1300-
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
1300+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
13011301
rtl.act(() => {
13021302
linkA.current!.click()
13031303
linkB.current!.click()
@@ -1345,7 +1345,7 @@ describe('React', () => {
13451345
)
13461346
expect(mapStateToPropsCalls).toBe(1)
13471347

1348-
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
1348+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
13491349
unmount()
13501350
expect(spy).toHaveBeenCalledTimes(0)
13511351
expect(mapStateToPropsCalls).toBe(1)
@@ -1380,7 +1380,7 @@ describe('React', () => {
13801380
})
13811381

13821382
expect(mapStateToPropsCalls).toBe(1)
1383-
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
1383+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
13841384
rtl.act(() => {
13851385
store.dispatch({ type: 'APPEND', body: 'a' })
13861386
})
@@ -1456,7 +1456,7 @@ describe('React', () => {
14561456
describe('Performance optimizations and bail-outs', () => {
14571457
it('should shallowly compare the selected state to prevent unnecessary updates', () => {
14581458
const store: Store = createStore(stringBuilder)
1459-
const spy = jest.fn(() => ({}))
1459+
const spy = vi.fn(() => ({}))
14601460
interface RenderProps {
14611461
string: string
14621462
}
@@ -1511,7 +1511,7 @@ describe('React', () => {
15111511

15121512
it('should shallowly compare the merged state to prevent unnecessary updates', () => {
15131513
const store: Store = createStore(stringBuilder)
1514-
const spy = jest.fn(() => ({}))
1514+
const spy = vi.fn(() => ({}))
15151515
interface PassObjType {
15161516
val?: string
15171517
prop?: string
@@ -2023,7 +2023,7 @@ describe('React', () => {
20232023
}
20242024
}
20252025

2026-
const mapStateToProps = jest.fn((state) => ({ count: state }))
2026+
const mapStateToProps = vi.fn((state) => ({ count: state }))
20272027

20282028
interface ChildrenTStateProps {
20292029
count: RootStateType
@@ -2089,7 +2089,7 @@ describe('React', () => {
20892089
}
20902090
type ChildNoDisPatch = {}
20912091
type ChildOwnProps = {}
2092-
const mapStateToProps = jest.fn((state) => ({ count: state }))
2092+
const mapStateToProps = vi.fn((state) => ({ count: state }))
20932093
class Child extends Component<ChildTStateProps> {
20942094
render() {
20952095
return <div>{this.props.count}</div>
@@ -2284,9 +2284,9 @@ describe('React', () => {
22842284
}
22852285
type ActionType = UnknownAction
22862286
type NoDispatchType = {}
2287-
const c3Spy = jest.fn()
2288-
const c2Spy = jest.fn()
2289-
const c1Spy = jest.fn()
2287+
const c3Spy = vi.fn()
2288+
const c2Spy = vi.fn()
2289+
const c1Spy = vi.fn()
22902290

22912291
type Comp3TStatePropsType = Store1State1Type
22922292
type Comp3NoDispatchType = NoDispatchType
@@ -2442,7 +2442,7 @@ describe('React', () => {
24422442
},
24432443
)(A)
24442444

2445-
const mapStateToPropsB = jest.fn((state) => ({ count: state }))
2445+
const mapStateToPropsB = vi.fn((state) => ({ count: state }))
24462446
class B extends Component {
24472447
render() {
24482448
return <ConnectedC {...this.props} />
@@ -2452,7 +2452,7 @@ describe('React', () => {
24522452
context: customContext,
24532453
})(B)
24542454

2455-
const mapStateToPropsC = jest.fn((state) => ({ count: state }))
2455+
const mapStateToPropsC = vi.fn((state) => ({ count: state }))
24562456
class C extends Component {
24572457
render() {
24582458
return <ConnectedD />
@@ -2467,7 +2467,7 @@ describe('React', () => {
24672467
}
24682468
type DNoDispatchType = {}
24692469
type DOwnPropsType = {}
2470-
const mapStateToPropsD = jest.fn((state) => ({ count: state }))
2470+
const mapStateToPropsD = vi.fn((state) => ({ count: state }))
24712471
class D extends Component<DTStatePropsType> {
24722472
render() {
24732473
return <div>{this.props.count}</div>
@@ -2812,7 +2812,7 @@ describe('React', () => {
28122812
describe('Error handling for invalid arguments', () => {
28132813
function renderWithBadConnect(Component: ElementType) {
28142814
const store = createStore(() => ({}))
2815-
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
2815+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
28162816

28172817
try {
28182818
rtl.render(
@@ -2885,7 +2885,7 @@ describe('React', () => {
28852885
if (!React.StrictMode) {
28862886
return
28872887
}
2888-
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
2888+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
28892889
const store: Store = createStore(stringBuilder)
28902890

28912891
class Container extends Component {
@@ -2917,7 +2917,7 @@ describe('React', () => {
29172917
})
29182918

29192919
it('should warn one-time-only that `pure` options has been removed', () => {
2920-
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
2920+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
29212921
const store: Store = createStore(stringBuilder)
29222922

29232923
class ContainerA extends Component {

test/components/hooks.spec.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*eslint-disable react/prop-types*/
22

3+
import '@testing-library/jest-dom/extend-expect'
4+
import * as rtl from '@testing-library/react'
35
import React from 'react'
6+
import type { AnyAction } from 'redux'
47
import { createStore } from 'redux'
58
import { Provider as ProviderMock, connect } from '../../src/index'
6-
import * as rtl from '@testing-library/react'
7-
import '@testing-library/jest-dom/extend-expect'
8-
import type { AnyAction } from 'redux'
99

1010
const IS_REACT_18 = React.version.startsWith('18')
1111

@@ -42,8 +42,8 @@ describe('React', () => {
4242
},
4343
)
4444

45-
const mapStateSpy1 = jest.fn()
46-
const renderSpy1 = jest.fn()
45+
const mapStateSpy1 = vi.fn()
46+
const renderSpy1 = vi.fn()
4747

4848
let component1StateList: number[]
4949

@@ -76,8 +76,8 @@ describe('React', () => {
7676

7777
const Component1 = component1Decorator(component1)
7878

79-
const mapStateSpy2 = jest.fn()
80-
const renderSpy2 = jest.fn()
79+
const mapStateSpy2 = vi.fn()
80+
const renderSpy2 = vi.fn()
8181

8282
interface Component2Tstate {
8383
mappedProp: string[]

test/hooks/useReduxContext.spec.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { renderHook } from '@testing-library/react-hooks'
22
import { createContext } from 'react'
33
import type { ReactReduxContextValue } from '../../src/components/Context'
44
import {
5-
createReduxContextHook,
6-
useReduxContext,
5+
createReduxContextHook,
6+
useReduxContext,
77
} from '../../src/hooks/useReduxContext'
88

99
describe('React', () => {
1010
describe('hooks', () => {
1111
describe('useReduxContext', () => {
1212
it('throws if component is not wrapped in provider', () => {
13-
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
13+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
1414

1515
const { result } = renderHook(() => useReduxContext())
1616

@@ -25,7 +25,7 @@ describe('React', () => {
2525
it('throws if component is not wrapped in provider', () => {
2626
const customContext = createContext<ReactReduxContextValue | null>(null)
2727
const useCustomReduxContext = createReduxContextHook(customContext)
28-
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
28+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
2929

3030
const { result } = renderHook(() => useCustomReduxContext())
3131

0 commit comments

Comments
 (0)