-
Notifications
You must be signed in to change notification settings - Fork 799
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(areComponentsEqual): fix behaviour (#829)
- Loading branch information
Showing
2 changed files
with
72 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { Component } from 'react' | ||
import reactHotLoader from '../src/reactHotLoader' | ||
import { areComponentsEqual } from '../src/utils.dev' | ||
|
||
reactHotLoader.patch(React) | ||
|
||
describe('utils (dev)', () => { | ||
describe('areComponentsEqual', () => { | ||
const createClasses = () => { | ||
class Component1 extends Component { | ||
render() { | ||
return 42 | ||
} | ||
} | ||
|
||
class Component2 extends Component { | ||
render() { | ||
return 43 | ||
} | ||
} | ||
|
||
return { Component1, Component2 } | ||
} | ||
|
||
const createStateless = () => { | ||
const Component1 = () => 42 | ||
const Component2 = () => 43 | ||
return { Component1, Component2 } | ||
} | ||
|
||
const testSuite = factory => { | ||
it('should compare non-registred components', () => { | ||
const { Component1, Component2 } = factory() | ||
|
||
const element1 = <Component1 /> | ||
const element2 = <Component2 /> | ||
|
||
expect(Component1 === Component2).toBe(false) | ||
expect(Component1 === element1.type).toBe(false) | ||
|
||
expect(areComponentsEqual(Component1, element1.type)).toBe(true) | ||
expect(areComponentsEqual(Component1, element2.type)).toBe(false) | ||
}) | ||
|
||
it('should compare registered components', () => { | ||
const { Component1, Component2 } = factory() | ||
|
||
reactHotLoader.register(Component1, 'Class1', 'util.dev') | ||
reactHotLoader.register(Component2, 'Class2', 'util.dev') | ||
|
||
const element1 = <Component1 /> | ||
const element2 = <Component2 /> | ||
|
||
expect(Component1 === Component2).toBe(false) | ||
expect(Component1 === element1.type).toBe(false) | ||
|
||
expect(areComponentsEqual(Component1, element1.type)).toBe(true) | ||
expect(areComponentsEqual(Component1, element2.type)).toBe(false) | ||
}) | ||
} | ||
|
||
describe('class based', () => testSuite(createClasses)) | ||
|
||
describe('function based', () => testSuite(createStateless)) | ||
}) | ||
}) |