Skip to content

Commit

Permalink
update test-jest for react 18
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Mar 9, 2023
1 parent 4287991 commit 7026d54
Show file tree
Hide file tree
Showing 7 changed files with 15,576 additions and 16,660 deletions.
32,182 changes: 15,549 additions & 16,633 deletions example/test-jest/package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions example/test-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"private": true,
"dependencies": {
"enzyme": "3.11.0",
"enzyme-adapter-react-16": "^1.1.1",
"i18next": "20.0.0",
"i18next-browser-languagedetector": "5.0.0",
"i18next-http-backend": "1.0.15",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-i18next": "11.5.1",
"react-scripts": "3.4.1"
"@cfaester/enzyme-adapter-react-18": "0.6.0",
"i18next": "22.4.11",
"i18next-browser-languagedetector": "7.0.1",
"i18next-http-backend": "2.1.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-i18next": "12.2.0",
"react-scripts": "5.0.1"
},
"scripts": {
"start": "react-scripts start",
Expand Down
8 changes: 4 additions & 4 deletions example/test-jest/src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
const root = createRoot(document.createElement('div'));
root.render(<App />);
root.unmount();
});
19 changes: 9 additions & 10 deletions example/test-jest/src/UseTranslationWithInterpolation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ jest.mock('react-i18next', () => ({
useTranslation: jest.fn(),
}));

const tSpy = jest.fn((str) => str);
const useTranslationSpy = useTranslation;

useTranslationSpy.mockReturnValue({
t: tSpy,
i18n: {
changeLanguage: () => new Promise(() => {}),
},
});

it('test render', () => {
const useTranslationSpy = useTranslation;
const tSpy = jest.fn((str) => str);
useTranslationSpy.mockReturnValue({
t: tSpy,
i18n: {
changeLanguage: () => new Promise(() => {}),
},
});

const mounted = mount(<UseTranslationWithInterpolation />);

// console.log(mounted.debug());
Expand Down
4 changes: 2 additions & 2 deletions example/test-jest/src/__mocks__/react-i18next.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const renderNodes = reactNodes => {
});
};

const useMock = [k => k, {}];
const useMock = [k => k, { changeLanguage: () => new Promise(() => {}) }];
useMock.t = k => k;
useMock.i18n = {};
useMock.i18n = { changeLanguage: () => new Promise(() => {}) };

module.exports = {
// this mock makes sure any components using the translate HoC receive the t function as a prop
Expand Down
5 changes: 3 additions & 2 deletions example/test-jest/src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import './index.css';
import App from './App';

import './i18n';

ReactDOM.render(<App />, document.getElementById('root'));
const root = createRoot(document.getElementById('root'));
root.render(<App />);
2 changes: 1 addition & 1 deletion example/test-jest/src/setupTests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import Adapter from '@cfaester/enzyme-adapter-react-18';

// without stubbing do this:
// import i18n from 'i18next';
Expand Down

0 comments on commit 7026d54

Please sign in to comment.