-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: driven * test: test driven * fix: ssr should not break * chore: clean up
- Loading branch information
Showing
3 changed files
with
68 additions
and
11 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { render } from '@testing-library/react'; | ||
import { renderToString } from 'react-dom/server'; | ||
import React from 'react'; | ||
import Drawer from '../src'; | ||
// import canUseDom from 'rc-util/lib/Dom/canUseDom' | ||
|
||
global.canUseDom = true; | ||
|
||
jest.mock('rc-util/lib/Dom/canUseDom', () => { | ||
// const canUseDom = jest.requireActual('rc-util/lib/Dom/canUseDom'); | ||
return () => global.canUseDom; | ||
}); | ||
|
||
describe('SSR', () => { | ||
beforeEach(() => { | ||
global.canUseDom = true; | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.useRealTimers(); | ||
}); | ||
|
||
it('hydrate should not crash', () => { | ||
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
|
||
const Demo = () => ( | ||
<Drawer open> | ||
<div className="bamboo" /> | ||
</Drawer> | ||
); | ||
|
||
global.canUseDom = false; | ||
const html = renderToString(<Demo />); | ||
|
||
expect(html).toBeFalsy(); | ||
|
||
global.canUseDom = true; | ||
|
||
const container = document.createElement('div'); | ||
container.innerHTML = html; | ||
document.body.appendChild(container); | ||
|
||
render(<Demo />, { container, hydrate: true }); | ||
|
||
expect(errSpy).not.toHaveBeenCalled(); | ||
|
||
errSpy.mockRestore(); | ||
}); | ||
}); |