-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
102 store passed to collected components (#103)
Fixes #102
- Loading branch information
1 parent
a4b4b52
commit f8eae2b
Showing
7 changed files
with
107 additions
and
5 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,50 @@ | ||
import React from 'react'; | ||
import { initStore, collect, WithStoreProp } from '../..'; | ||
import * as testUtils from '../testUtils'; | ||
|
||
beforeEach(() => { | ||
initStore(); | ||
}); | ||
|
||
/** | ||
* Passing anything from the store into a collected component can be trouble. | ||
* @see https://github.com/davidgilbertson/react-recollect/issues/102 | ||
*/ | ||
it('should error when sharing between collected components', () => { | ||
initStore({ | ||
tasks: [ | ||
{ | ||
id: 1, | ||
name: 'Task one', | ||
}, | ||
], | ||
}); | ||
|
||
const ChildComponent = ({ task }: any) => <div>{task.name}</div>; | ||
const ChildComponentCollected = collect(ChildComponent); | ||
|
||
// Shouldn't matter how many levels deep the prop is passed | ||
const MiddleComponent = ({ task }: any) => ( | ||
<div> | ||
<ChildComponentCollected task={task} /> | ||
</div> | ||
); | ||
|
||
const ParentComponent = collect(({ store }: WithStoreProp) => ( | ||
<div> | ||
{!!store.tasks && | ||
store.tasks.map((task) => ( | ||
<MiddleComponent key={task.id} task={task} /> | ||
))} | ||
</div> | ||
)); | ||
|
||
const errorMessage = testUtils.expectToLogError(() => { | ||
testUtils.renderStrict(<ParentComponent />); | ||
}); | ||
|
||
// Just a partial match... | ||
expect(errorMessage).toMatch( | ||
'Either remove the collect() wrapper from <ChildComponent/>, or remove the "task" prop' | ||
); | ||
}); |