Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #54 - Breaks child.type comparisons #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,67 @@ test('render to static markup', () => {
const string = ReactDOMServer.renderToStaticMarkup(<MyComponent/>)
expect(string).toBe('<div>hi!</div>')
})

describe('React.children', () => {
test('count', () => {
let countOfChildren = null

const ExampleChildComponent = () => <div>hi :D</div>
ExampleChildComponent.whyDidYouRender = true

const ExampleComponent = ({children}) => {
countOfChildren = React.Children.count(children)
return (
<div>
{children}
</div>
)
}

ExampleComponent.whyDidYouRender = true

rtl.render(
<ExampleComponent>
<ExampleChildComponent>child_1</ExampleChildComponent>
<ExampleChildComponent>child_2</ExampleChildComponent>
<ExampleChildComponent>child_3</ExampleChildComponent>
</ExampleComponent>
)

expect(countOfChildren).toBe(3)
})

test('children types', () => {
let childrenTypes = null
const ExampleChildComponent = () => <div>hi :D</div>

ExampleChildComponent.whyDidYouRender = true

const ExampleComponent = ({children}) => {
childrenTypes = React.Children.map(children, child => {
return child.type
})
return (
<div>
{children}
</div>
)
}

ExampleComponent.whyDidYouRender = true

rtl.render(
<ExampleComponent>
<ExampleChildComponent>child_1</ExampleChildComponent>
<ExampleChildComponent>child_2</ExampleChildComponent>
<ExampleChildComponent>child_3</ExampleChildComponent>
</ExampleComponent>
)

expect(childrenTypes).toEqual([
ExampleChildComponent,
ExampleChildComponent,
ExampleChildComponent
])
})
})