Skip to content

Commit 12b61ae

Browse files
committed
chore: migrate tests
1 parent 12a1e1f commit 12b61ae

19 files changed

+612
-47
lines changed

.gitignore

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
# Created by https://www.toptal.com/developers/gitignore/api/react,windows,linux,macos,node,code
2-
# Edit at https://www.toptal.com/developers/gitignore?templates=react,windows,linux,macos,node,code
3-
4-
#!! ERROR: code is undefined. Use list command to see defined gitignore types !!#
1+
# Created by https://www.toptal.com/developers/gitignore/api/react,windows,linux,macos,visualstudiocode,node
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=react,windows,linux,macos,visualstudiocode,node
53

64
### Linux ###
75
*~
@@ -204,6 +202,25 @@ psd
204202
thumb
205203
sketch
206204

205+
### VisualStudioCode ###
206+
.vscode/*
207+
!.vscode/settings.json
208+
!.vscode/tasks.json
209+
!.vscode/launch.json
210+
!.vscode/extensions.json
211+
!.vscode/*.code-snippets
212+
213+
# Local History for Visual Studio Code
214+
.history/
215+
216+
# Built Visual Studio Code Extensions
217+
*.vsix
218+
219+
### VisualStudioCode Patch ###
220+
# Ignore all local history of files
221+
.history
222+
.ionide
223+
207224
### Windows ###
208225
# Windows thumbnail cache files
209226
Thumbs.db
@@ -230,6 +247,9 @@ $RECYCLE.BIN/
230247
# Windows shortcuts
231248
*.lnk
232249

233-
# End of https://www.toptal.com/developers/gitignore/api/react,windows,linux,macos,node,code
250+
# End of https://www.toptal.com/developers/gitignore/api/react,windows,linux,macos,visualstudiocode,node
251+
234252

235253
.pnpm-store
254+
.nx/cache
255+
.nx/workspace-data

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typescript.tsdk": "node_modules/typescript/lib"
3+
}

packages/react-dsv-import/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
"react": "^18.0.0 || ^19.0.0",
2828
"react-dom": "^18.0.0 || ^19.0.0"
2929
},
30-
"dependencies": {},
31-
"scripts": {}
30+
"scripts": {},
31+
"devDependencies": {
32+
"@testing-library/jest-dom": "^6.6.3",
33+
"@testing-library/react": "^16.1.0",
34+
"@types/react": "^19.0.1",
35+
"jsdom": "^25.0.1"
36+
}
3237
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom';

packages/react-dsv-import/src/DSVImport.test.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { ColumnType } from './models/column';
44
import { DSVImport } from '.';
55
import { useDSVImport } from './features/context';
66
import { ValidationError } from './models/validation';
7+
import { vi } from 'vitest';
8+
import { describe } from 'vitest';
9+
import { expect } from 'vitest';
10+
import { it } from 'vitest';
711

812
describe('DSVImport', () => {
913
type TestType = { forename: string; surname: string; email: string };
@@ -32,15 +36,14 @@ describe('DSVImport', () => {
3236

3337
const renderComponent = (props: Props<TestType>) => {
3438
return render(
35-
// eslint-disable-next-line react/jsx-props-no-spreading
3639
<DSVImport<TestType> {...props}>
3740
<MinimalTextareaInput />
3841
</DSVImport>
3942
);
4043
};
4144

4245
it('should invoke the onChange callback', () => {
43-
const onChangeMock = jest.fn();
46+
const onChangeMock = vi.fn();
4447
const { container } = renderComponent({ columns, onChange: onChangeMock });
4548
const textarea = container.querySelector('textarea');
4649

@@ -52,7 +55,7 @@ describe('DSVImport', () => {
5255
});
5356

5457
it('should invoke the onValidation callback', () => {
55-
const onValidationMock = jest.fn();
58+
const onValidationMock = vi.fn();
5659
const { container } = renderComponent({ columns, onValidation: onValidationMock });
5760
const textarea = container.querySelector('textarea');
5861

packages/react-dsv-import/src/components/inputs/TextareaInput.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ describe('TextareaInput', () => {
1010
const state: State<TestType> = { columns };
1111
const Context = getDSVImportContext<TestType>();
1212

13-
const dispatchMock = jest.fn(() => state);
13+
const dispatchMock = vi.fn(() => state);
1414

1515
const renderComponent = () => {
1616
return render(
17-
// eslint-disable-next-line react/jsx-no-constructed-context-values
1817
<Context.Provider value={[state, dispatchMock]}>
1918
<TextareaInput />
2019
</Context.Provider>

packages/react-dsv-import/src/components/previews/TablePreview.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ColumnType } from '../../models/column';
33
import { TablePreview } from './TablePreview';
44
import { State } from '../../models/state';
55
import { getDSVImportContext } from '../../features/context';
6+
import '@testing-library/jest-dom';
67

78
describe('TablePreview', () => {
89
type TestType = { forename: string; surname: string; email: string };
@@ -14,11 +15,10 @@ describe('TablePreview', () => {
1415
const defaultState: State<TestType> = { columns };
1516
const Context = getDSVImportContext<TestType>();
1617

17-
const dispatchMock = jest.fn(() => defaultState);
18+
const dispatchMock = vi.fn(() => defaultState);
1819

1920
const renderComponent = (state = defaultState) => {
2021
return render(
21-
// eslint-disable-next-line react/jsx-no-constructed-context-values
2222
<Context.Provider value={[state, dispatchMock]}>
2323
<TablePreview />
2424
</Context.Provider>

packages/react-dsv-import/src/components/previews/TablePreview.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export function TablePreview({ className }: TablePreviewProps) {
3333
<tbody>
3434
{context.parsed
3535
? context.parsed.map((row, rowIndex) => (
36-
// eslint-disable-next-line react/no-array-index-key
3736
<tr key={rowIndex}>
3837
{context.columns.map((column) => {
3938
return (

packages/react-dsv-import/src/features/context.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { useContext } from 'react';
22
import { renderHook } from '@testing-library/react';
33
import { reducer, getDSVImportContext } from './context';
44
import { State } from '../models/state';
5+
import { describe } from 'vitest';
6+
import { it } from 'vitest';
7+
import { expect } from 'vitest';
58

69
describe('context', () => {
710
type TestType = unknown;

packages/react-dsv-import/src/middlewares/middleware.test.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import { describe } from 'vitest';
12
import { ColumnType } from '../models/column';
23
import { State } from '../models/state';
34
import { applyMiddlewares } from './middleware';
5+
import { it } from 'vitest';
6+
import { vi } from 'vitest';
7+
import { expect } from 'vitest';
48

59
describe('middleware', () => {
610
type TestType = { forename: string; surname: string; email: string };
@@ -12,10 +16,10 @@ describe('middleware', () => {
1216
const defaultState: State<TestType> = { columns };
1317

1418
it('should dispatch to all middlewares', () => {
15-
const dispatchMock = jest.fn();
16-
const middlewareAMock = jest.fn();
17-
const middlewareBMock = jest.fn();
18-
const middlewareCMock = jest.fn();
19+
const dispatchMock = vi.fn();
20+
const middlewareAMock = vi.fn();
21+
const middlewareBMock = vi.fn();
22+
const middlewareCMock = vi.fn();
1923
const enhancedDispatch = applyMiddlewares(
2024
defaultState,
2125
dispatchMock,
@@ -31,12 +35,12 @@ describe('middleware', () => {
3135
});
3236

3337
it('should forward a dispatch to other middlewares', () => {
34-
const dispatchMock = jest.fn();
35-
const middlewareAMock = jest.fn((_state, dispatch) => {
38+
const dispatchMock = vi.fn();
39+
const middlewareAMock = vi.fn((_state, dispatch) => {
3640
dispatch({ type: 'sequentCall' });
3741
});
38-
const middlewareBMock = jest.fn();
39-
const middlewareCMock = jest.fn();
42+
const middlewareBMock = vi.fn();
43+
const middlewareCMock = vi.fn();
4044
const enhancedDispatch = applyMiddlewares(
4145
defaultState,
4246
dispatchMock,
@@ -54,14 +58,14 @@ describe('middleware', () => {
5458
});
5559

5660
it('should not call a middleware twice', () => {
57-
const dispatchMock = jest.fn();
58-
const middlewareAMock = jest.fn((_state, dispatch) => {
61+
const dispatchMock = vi.fn();
62+
const middlewareAMock = vi.fn((_state, dispatch) => {
5963
dispatch({ type: 'sequentCall' });
6064
});
61-
const middlewareBMock = jest.fn((_state, dispatch) => {
65+
const middlewareBMock = vi.fn((_state, dispatch) => {
6266
dispatch({ type: 'sequentCall' });
6367
});
64-
const middlewareCMock = jest.fn((_state, dispatch) => {
68+
const middlewareCMock = vi.fn((_state, dispatch) => {
6569
dispatch({ type: 'sequentCall' });
6670
});
6771
const enhancedDispatch = applyMiddlewares(

0 commit comments

Comments
 (0)