Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
feat(deps): upgrade to react 17
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Upgrade from React 16 to 17
  • Loading branch information
10xLaCroixDrinker authored and JAdshead committed Jul 20, 2022
1 parent 0d653b6 commit d927a7f
Show file tree
Hide file tree
Showing 26 changed files with 139 additions and 1,068 deletions.
42 changes: 0 additions & 42 deletions __tests__/client/__snapshots__/initClient.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,3 @@ Immutable.Map {
},
}
`;

exports[`initClient should use ReactDOM.render if renderMode is "render" 1`] = `
<Provider
store={
Object {
"@@observable": [Function],
"dispatch": [Function],
"getState": [Function],
"modules": Immutable.Map {},
"rebuildReducer": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
}
}
>
<Router
render={[Function]}
testProp="test"
/>
</Provider>
`;

exports[`initClient should use strict mode 1`] = `
<Provider
store={
Object {
"@@observable": [Function],
"dispatch": [Function],
"getState": [Function],
"modules": Immutable.Map {},
"rebuildReducer": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
}
}
>
<Router
render={[Function]}
testProp="test"
/>
</Provider>
`;
67 changes: 5 additions & 62 deletions __tests__/client/initClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@
* permissions and limitations under the License.
*/

import { shallow } from 'enzyme';
import { fromJS } from 'immutable';

jest.mock('react', () => {
const StrictMode = ({ children }) => children;
const react = jest.requireActual('react');
return { ...react, StrictMode };
});

jest.mock('@americanexpress/one-app-router', () => {
const reactRouter = jest.requireActual('@americanexpress/one-app-router');
jest.spyOn(reactRouter, 'matchPromise');
Expand Down Expand Up @@ -83,16 +76,12 @@ describe('initClient', () => {
expect.assertions(1);
const { loadPrerenderScripts } = require('../../src/client/prerender');
const mockError = new Error('This is a test error!!!');
loadPrerenderScripts.mockReturnValue(Promise.reject(mockError));
loadPrerenderScripts.mockImplementationOnce(() => { throw mockError; });

const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const initClient = require('../../src/client/initClient').default;

try {
await initClient();
} catch (_error) {
// do nothing
}
await initClient();
expect(consoleErrorSpy).toHaveBeenCalledWith(mockError);
});

Expand All @@ -119,27 +108,6 @@ describe('initClient', () => {
expect(promiseResolveSpy).toHaveBeenCalled();
});

it('handles rejected promises', async () => {
expect.assertions(2);
const promiseRejectionSpy = jest.spyOn(Promise, 'reject');
const consoleErrorSpy = jest.spyOn(console, 'error');
const testError = new Error('something went wrong');

const { matchPromise } = require('@americanexpress/one-app-router');
matchPromise.mockImplementationOnce(
() => Promise.reject(testError)
);

const { loadPrerenderScripts } = require('../../src/client/prerender');
loadPrerenderScripts.mockReturnValueOnce(Promise.resolve());

const initClient = require('../../src/client/initClient').default;

await initClient();
expect(consoleErrorSpy).toHaveBeenCalledWith(testError);
expect(promiseRejectionSpy).toHaveBeenCalled();
});

it('should set up the global redux store and kick off rendering', async () => {
expect.assertions(2);
const promiseResolveSpy = jest.spyOn(Promise, 'resolve');
Expand All @@ -162,35 +130,10 @@ describe('initClient', () => {
expect(promiseResolveSpy).toHaveBeenCalled();
});

it('should use strict mode', async () => {
expect.assertions(1);
const promiseResolveSpy = jest.spyOn(Promise, 'resolve');
const { hydrate } = require('react-dom');

document.getElementById = jest.fn(() => ({ remove: jest.fn() }));

const { matchPromise } = require('@americanexpress/one-app-router');
matchPromise.mockImplementationOnce(() => Promise.resolve({
redirectLocation: null,
renderProps: { testProp: 'test' },
}));

const { loadPrerenderScripts } = require('../../src/client/prerender');
loadPrerenderScripts.mockReturnValueOnce(Promise.resolve());
promiseResolveSpy.mockRestore();

const initClient = require('../../src/client/initClient').default;

await initClient();

const tree = shallow(hydrate.mock.calls[0][0]);
expect(tree).toMatchSnapshot();
});

it('should use ReactDOM.render if renderMode is "render"', async () => {
expect.assertions(1);
const promiseResolveSpy = jest.spyOn(Promise, 'resolve');
const { render } = require('react-dom');
const { render, hydrate } = require('react-dom');

document.getElementById = jest.fn(() => ({ remove: jest.fn() }));

Expand All @@ -211,8 +154,8 @@ describe('initClient', () => {

await initClient();

const tree = shallow(render.mock.calls[0][0]);
expect(tree).toMatchSnapshot();
expect(render).toHaveBeenCalled();
expect(hydrate).not.toHaveBeenCalled();
});

it('should load pwa script', async () => {
Expand Down
6 changes: 5 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
*/

module.exports = {
preset: 'amex-jest-preset-react',
preset: 'amex-jest-preset',
testEnvironment: 'jsdom',
collectCoverageFrom: [
'src/**/*.{js,jsx}',
],
coveragePathIgnorePatterns: [
'src/client/polyfill',
'src/server/polyfill',
Expand Down
Loading

0 comments on commit d927a7f

Please sign in to comment.