-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1247 from gaearon/may-fixes
May fixes
- Loading branch information
Showing
17 changed files
with
260 additions
and
69 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
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
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
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
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,63 @@ | ||
/* eslint-env browser */ | ||
/* eslint-disable no-lone-blocks, global-require */ | ||
import 'babel-polyfill'; | ||
import React from 'react'; | ||
import TestRenderer from 'react-test-renderer'; | ||
import ReactHotLoader, { AppContainer, setConfig } from '../../../src/index.dev'; | ||
import { configureGeneration } from '../../../src/global/generation'; | ||
|
||
// jest.mock('react-dom', () => require('@hot-loader/react-dom')); | ||
|
||
describe(`Hooks: useContext`, () => { | ||
beforeEach(() => { | ||
ReactHotLoader.reset(); | ||
setConfig({ | ||
ignoreSFC: true, | ||
}); | ||
configureGeneration(1, 1); | ||
}); | ||
|
||
if (React.useContext) { | ||
it('use', () => { | ||
let failed = false; | ||
const context = React.createContext(0); | ||
const Wrapper = () => { | ||
const ctx = React.useContext(context); | ||
if (ctx) { | ||
return `pass ${ctx}`; | ||
} | ||
failed = true; | ||
return 'fail'; | ||
}; | ||
ReactHotLoader.register(Wrapper, 'wrapper', 'hook-test'); | ||
|
||
const wrapper = TestRenderer.create( | ||
<AppContainer update> | ||
<context.Provider value={1}> | ||
<Wrapper /> | ||
</context.Provider> | ||
</AppContainer>, | ||
); | ||
|
||
expect(wrapper.toJSON()).toEqual('pass 1'); | ||
expect(failed).toBe(false); | ||
|
||
{ | ||
ReactHotLoader.register(Wrapper, 'wrapper', 'hook-test'); | ||
wrapper.update( | ||
<AppContainer update> | ||
<context.Provider value={2}> | ||
<Wrapper /> | ||
</context.Provider> | ||
</AppContainer>, | ||
); | ||
expect(wrapper.toJSON()).toEqual('pass 2'); | ||
expect(failed).toBe(false); | ||
} | ||
}); | ||
} else { | ||
it('target platform does not support useContext', () => { | ||
expect(true).toBe(true); | ||
}); | ||
} | ||
}); |
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,73 @@ | ||
/* eslint-env browser */ | ||
import 'babel-polyfill'; | ||
import React from 'react'; | ||
import TestRenderer from 'react-test-renderer'; | ||
import ReactHotLoader, { AppContainer } from '../../../src/index.dev'; | ||
import { configureGeneration } from '../../../src/global/generation'; | ||
|
||
// jest.mock('react-dom', () => require('@hot-loader/react-dom')); | ||
|
||
describe(`React.memo`, () => { | ||
beforeEach(() => { | ||
ReactHotLoader.reset(); | ||
configureGeneration(1, 1); | ||
}); | ||
|
||
const snapShot = { | ||
children: ['this is component 2'], | ||
props: {}, | ||
type: 'div', | ||
}; | ||
|
||
if (React.memo) { | ||
it('memo wrapping functional component', () => { | ||
const Memo = React.memo(() => <div>this is component 1</div>); | ||
ReactHotLoader.register(Memo, 'memo', 'memo-test'); | ||
|
||
const wrapper = TestRenderer.create( | ||
<AppContainer> | ||
<Memo /> | ||
</AppContainer>, | ||
); | ||
|
||
{ | ||
const Memo = React.memo(() => <div>this is component 2</div>); | ||
ReactHotLoader.register(Memo, 'memo', 'memo-test'); | ||
wrapper.update( | ||
<AppContainer update> | ||
<Memo test /> | ||
</AppContainer>, | ||
); | ||
|
||
expect(wrapper.toJSON()).toEqual(snapShot); | ||
} | ||
}); | ||
|
||
it('memo wrapping forwardRef component', () => { | ||
const Memo = React.memo(React.forwardRef(() => <div>this is component 1</div>)); | ||
ReactHotLoader.register(Memo, 'memo', 'memo-test'); | ||
|
||
const wrapper = TestRenderer.create( | ||
<AppContainer> | ||
<Memo /> | ||
</AppContainer>, | ||
); | ||
|
||
{ | ||
const Memo = React.memo(React.forwardRef(() => <div>this is component 2</div>)); | ||
ReactHotLoader.register(Memo, 'memo', 'memo-test'); | ||
wrapper.update( | ||
<AppContainer update> | ||
<Memo /> | ||
</AppContainer>, | ||
); | ||
|
||
expect(wrapper.toJSON()).toEqual(snapShot); | ||
} | ||
}); | ||
} else { | ||
it('target platform does not support React.memo', () => { | ||
expect(true).toBe(true); | ||
}); | ||
} | ||
}); |
Oops, something went wrong.