-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67d6fc6
commit 1eb9b6c
Showing
5 changed files
with
143 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/s2-react/__tests__/unit/utils/react-render-16-spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* eslint-disable react/no-deprecated */ | ||
jest.mock('react', () => { | ||
return { | ||
...jest.requireActual('react'), | ||
version: '16.9.0', | ||
}; | ||
}); | ||
|
||
jest.mock('react-dom', () => { | ||
return { | ||
...jest.requireActual('react-dom'), | ||
render: jest.fn(), | ||
unmountComponentAtNode: jest.fn(), | ||
createRoot: jest.fn(() => { | ||
return { | ||
unmount: jest.fn(), | ||
}; | ||
}), | ||
}; | ||
}); | ||
|
||
import { | ||
forceClearContent, | ||
isLegacyReactVersion, | ||
reactRender, | ||
reactUnmount, | ||
} from '@/utils/reactRender'; | ||
import ReactDOM from 'react-dom'; | ||
import { getContainer } from '../../util/helpers'; | ||
|
||
const element = null; | ||
const container = getContainer(); | ||
|
||
describe('React 16 Render Tests', () => { | ||
test('should get correctly legacy react version', () => { | ||
expect(isLegacyReactVersion()).toBeTruthy(); | ||
}); | ||
|
||
test('should only call legacy render', () => { | ||
reactRender(element, container); | ||
|
||
expect(ReactDOM.render).toHaveBeenCalledTimes(1); | ||
// @ts-ignore | ||
expect(ReactDOM.createRoot).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
test('should only call legacy unmount', () => { | ||
reactUnmount(container); | ||
|
||
expect(ReactDOM.unmountComponentAtNode).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('should only call modern render for force clear content', () => { | ||
const root = reactRender(element, container); | ||
|
||
forceClearContent(container); | ||
|
||
expect(ReactDOM.unmountComponentAtNode).toHaveBeenCalledTimes(1); | ||
expect(ReactDOM.render).toHaveBeenCalledTimes(1); | ||
expect(root).not.toBeDefined(); | ||
}); | ||
}); |
66 changes: 66 additions & 0 deletions
66
packages/s2-react/__tests__/unit/utils/react-render-18-spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* eslint-disable jest/no-standalone-expect */ | ||
/* eslint-disable react/no-deprecated */ | ||
jest.mock('react', () => { | ||
return { | ||
...jest.requireActual('react'), | ||
version: '18.3.0', | ||
}; | ||
}); | ||
|
||
jest.mock('react-dom', () => { | ||
return { | ||
...jest.requireActual('react-dom'), | ||
render: jest.fn(), | ||
unmountComponentAtNode: jest.fn(), | ||
createRoot: jest.fn(() => { | ||
return { | ||
render: jest.fn(), | ||
unmount: jest.fn(), | ||
}; | ||
}), | ||
}; | ||
}); | ||
|
||
import { | ||
forceClearContent, | ||
isLegacyReactVersion, | ||
reactRender, | ||
reactUnmount, | ||
} from '@/utils/reactRender'; | ||
import ReactDOM from 'react-dom'; | ||
import { getContainer } from '../../util/helpers'; | ||
|
||
const element = null; | ||
const container = getContainer(); | ||
|
||
describe('React 18 Render Tests', () => { | ||
test('should get correctly legacy react version', () => { | ||
expect(isLegacyReactVersion()).toBeFalsy(); | ||
}); | ||
|
||
test('should only call modern render', () => { | ||
reactRender(element, container); | ||
|
||
expect(ReactDOM.render).toHaveBeenCalledTimes(0); | ||
// @ts-ignore | ||
expect(ReactDOM.createRoot).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('should only call modern unmount', () => { | ||
const root = reactRender(element, container); | ||
|
||
reactUnmount(container); | ||
|
||
expect(ReactDOM.unmountComponentAtNode).toHaveBeenCalledTimes(0); | ||
expect(root).not.toBeDefined(); | ||
}); | ||
|
||
test('should only call modern render for force clear content', () => { | ||
const root = forceClearContent(container); | ||
|
||
expect(ReactDOM.unmountComponentAtNode).toHaveBeenCalledTimes(0); | ||
expect(ReactDOM.render).toHaveBeenCalledTimes(0); | ||
expect(root.unmount).toHaveBeenCalledTimes(0); | ||
expect(root.render).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters