Skip to content

Commit

Permalink
Fix most tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spautz committed May 8, 2023
1 parent c7363aa commit 8a8c32b
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 58 deletions.
5 changes: 4 additions & 1 deletion packages/redux-to-recoil/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,16 @@
"immutable-path": "^1.0.1"
},
"devDependencies": {
"@testing-library/react": "14.0.0",
"@testing-library/react": "13.4.0",
"@testing-library/react-hooks": "8.0.1",
"@types/node": "20.1.0",
"@types/react": "18.2.6",
"@types/react-redux": "7.1.25",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-recoil-hooks-testing-library": "0.1.0",
"react-redux": "8.0.5",
"react-test-renderer": "18.2.0",
"recoil": "0.7.7",
"redux": "4.2.1",
"reselect": "4.1.8"
Expand Down
2 changes: 1 addition & 1 deletion packages/redux-to-recoil/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import '@testing-library/jest-dom';
// import '@testing-library/jest-dom';
12 changes: 6 additions & 6 deletions packages/redux-to-recoil/src/__tests__/components.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Store } from 'redux';
import { Provider } from 'react-redux';
import { RecoilRoot } from 'recoil';
import { render } from '@testing-library/react';
import { describe, beforeEach, expect, it } from 'vitest';
import { describe, beforeEach, afterEach, expect, it, vitest } from 'vitest';

import { reduxStoreRef, resetStateBetweenTests } from '../internals';
import { SyncReduxToRecoil } from '../SyncReduxToRecoil';
Expand All @@ -16,8 +16,8 @@ describe('read Redux state through Recoil', () => {
const originalConsoleWarn: typeof console.warn = console.warn;

beforeEach(() => {
jest.restoreAllMocks();
jest.resetModules();
vitest.restoreAllMocks();
vitest.resetModules();

resetStateBetweenTests();
testStore = createTestStore();
Expand All @@ -28,7 +28,7 @@ describe('read Redux state through Recoil', () => {
});

it('needs to be within a Redux context', () => {
const consoleErrorSpy = jest.spyOn(console, 'error').mockReturnValue();
const consoleErrorSpy = vitest.spyOn(console, 'error').mockReturnValue();

expect(() => {
render(
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('read Redux state through Recoil', () => {
});

it('needs to be within a Recoil context', () => {
const consoleErrorSpy = jest.spyOn(console, 'error').mockReturnValue();
const consoleErrorSpy = vitest.spyOn(console, 'error').mockReturnValue();

expect(() => {
render(
Expand All @@ -83,7 +83,7 @@ describe('read Redux state through Recoil', () => {
});

it('warns if SyncReduxToRecoil is given invalid options', () => {
const consoleWarnSpy = jest.spyOn(console, 'warn').mockReturnValue();
const consoleWarnSpy = vitest.spyOn(console, 'warn').mockReturnValue();

const { rerender } = render(
<Provider store={testStore}>
Expand Down
8 changes: 4 additions & 4 deletions packages/redux-to-recoil/src/__tests__/readState.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Store } from 'redux';
import { Provider } from 'react-redux';
import { RecoilState, useRecoilValue } from 'recoil';
import { act, renderRecoilHook } from 'react-recoil-hooks-testing-library';
import { describe, beforeEach, expect, it } from 'vitest';
import { describe, beforeEach, afterEach, expect, it, vitest } from 'vitest';

import { atomFromRedux } from '../atomFromRedux';

Expand All @@ -23,8 +23,8 @@ describe('read Redux state through Recoil', () => {
const originalConsoleError: typeof console.error = console.error;
const originalConsoleWarn: typeof console.warn = console.warn;
beforeEach(() => {
jest.restoreAllMocks();
jest.resetModules();
vitest.restoreAllMocks();
vitest.resetModules();

resetStateBetweenTests();
testStore = createTestStore();
Expand Down Expand Up @@ -123,7 +123,7 @@ describe('read Redux state through Recoil', () => {
});

it('warns and returns undefined if readEnabled has never been on', () => {
const consoleWarnSpy = jest.spyOn(console, 'warn').mockReturnValueOnce();
const consoleWarnSpy = vitest.spyOn(console, 'warn').mockReturnValueOnce();

const nullStore = createTestStore(null);
const NullReduxProviderWrapper = createTestWrapper(nullStore);
Expand Down
6 changes: 3 additions & 3 deletions packages/redux-to-recoil/src/__tests__/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Selector } from 'react-redux';
import { RecoilState, selector, useRecoilValue } from 'recoil';
import { createSelector } from 'reselect';
import { renderRecoilHook } from 'react-recoil-hooks-testing-library';
import { describe, beforeEach, expect, it } from 'vitest';
import { describe, beforeEach, afterEach, expect, it, vitest } from 'vitest';

import { ReduxState, resetStateBetweenTests } from '../internals';
import { atomFromRedux } from '../atomFromRedux';
Expand All @@ -19,8 +19,8 @@ describe('selectors', () => {
const originalConsoleError: typeof console.error = console.error;
const originalConsoleWarn: typeof console.warn = console.warn;
beforeEach(() => {
jest.restoreAllMocks();
jest.resetModules();
vitest.restoreAllMocks();
vitest.resetModules();

resetStateBetweenTests();
testStore = createTestStore();
Expand Down
22 changes: 11 additions & 11 deletions packages/redux-to-recoil/src/__tests__/writeState.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Store } from 'redux';
import { Provider } from 'react-redux';
import { RecoilState, useRecoilState, useSetRecoilState } from 'recoil';
import { act, renderRecoilHook } from 'react-recoil-hooks-testing-library';
import { describe, beforeEach, expect, it } from 'vitest';
import { describe, beforeEach, afterEach, expect, it, vitest } from 'vitest';

import { atomFromRedux } from '../atomFromRedux';

Expand All @@ -18,10 +18,10 @@ describe('write Redux state through Recoil', () => {
const originalConsoleError: typeof console.error = console.error;
const originalConsoleWarn: typeof console.warn = console.warn;
beforeEach(() => {
jest.restoreAllMocks();
jest.resetModules();
jest.clearAllTimers();
jest.useRealTimers();
vitest.restoreAllMocks();
vitest.resetModules();
vitest.clearAllTimers();
vitest.useRealTimers();

resetStateBetweenTests();
testStore = createTestStore();
Expand Down Expand Up @@ -113,13 +113,13 @@ describe('write Redux state through Recoil', () => {

expect(() => {
act(() => {
setValue1(123);
setValue1(() => 123);
});
}).toThrowError('Cannot dispatch to Redux because <SyncReduxToRecoil> is not mounted');
});

it('emits an error and does nothing if writeEnabled is off', () => {
const consoleErrorSpy = jest.spyOn(console, 'error').mockReturnValueOnce();
const consoleErrorSpy = vitest.spyOn(console, 'error').mockReturnValueOnce();

const value1Atom: RecoilState<number> = atomFromRedux<number>('value1');
const useValue1Atom = () => useRecoilState(value1Atom);
Expand Down Expand Up @@ -150,7 +150,7 @@ describe('write Redux state through Recoil', () => {
});

it('can batch its writes to Redux', () => {
jest.useFakeTimers();
vitest.useFakeTimers();

const value1Atom: RecoilState<number> = atomFromRedux<number>('value1');
const useValue1Atom = () => useRecoilState(value1Atom);
Expand All @@ -177,7 +177,7 @@ describe('write Redux state through Recoil', () => {
expect(testStore.getState().value1).toBe(VALUE1_DEFAULT);

act(() => {
jest.runAllTimers();
vitest.runAllTimers();
});

rerender();
Expand All @@ -188,7 +188,7 @@ describe('write Redux state through Recoil', () => {
});

it('queues up multiple writes when batching', () => {
jest.useFakeTimers();
vitest.useFakeTimers();

const value1Atom: RecoilState<number> = atomFromRedux<number>('value1');
const value2Atom: RecoilState<number> = atomFromRedux<number>('value2');
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('write Redux state through Recoil', () => {
expect(testStore.getState().value2).toBe(VALUE2_DEFAULT);

act(() => {
jest.runAllTimers();
vitest.runAllTimers();
});

rerender();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { set as setPath } from 'immutable-path/dist/immutable-object-path';
import { set as setPath } from 'immutable-path';

import { ChangeEntry, ReduxState } from './types';

Expand Down
Loading

0 comments on commit 8a8c32b

Please sign in to comment.