-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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 #7981 from marmelab/fix-admin-children-function-type
[TypeScript] Fix `<Admin>` used with function child and fragment does not compile
- Loading branch information
Showing
2 changed files
with
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import * as React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { CoreAdmin } from './CoreAdmin'; | ||
import { Resource } from './Resource'; | ||
|
||
describe('CoreAdmin', () => { | ||
describe('children', () => { | ||
it('should accept Resources as children', async () => { | ||
const Foo = () => <div>Foo</div>; | ||
const App = () => ( | ||
<CoreAdmin> | ||
<Resource name="posts" list={Foo} /> | ||
<Resource name="comments" list={Foo} /> | ||
</CoreAdmin> | ||
); | ||
render(<App />); | ||
await screen.findByText('Foo'); | ||
}); | ||
it('should accept a function returning an array of Resources as children', async () => { | ||
const Foo = () => <div>Foo</div>; | ||
const App = () => ( | ||
<CoreAdmin> | ||
{() => [ | ||
<Resource name="posts" key="posts" list={Foo} />, | ||
<Resource name="comments" key="comments" list={Foo} />, | ||
]} | ||
</CoreAdmin> | ||
); | ||
render(<App />); | ||
await screen.findByText('Foo'); | ||
}); | ||
it('should accept a function returning a fragment of Resources as children', async () => { | ||
const Foo = () => <div>Foo</div>; | ||
const App = () => ( | ||
<CoreAdmin> | ||
{() => ( | ||
<> | ||
<Resource name="posts" list={Foo} /> | ||
<Resource name="comments" list={Foo} /> | ||
</> | ||
)} | ||
</CoreAdmin> | ||
); | ||
render(<App />); | ||
await screen.findByText('Foo'); | ||
}); | ||
it('should accept a function returning a promise for an array of Resources as children', async () => { | ||
const Foo = () => <div>Foo</div>; | ||
const App = () => ( | ||
<CoreAdmin> | ||
{() => | ||
Promise.resolve([ | ||
<Resource name="posts" key="posts" list={Foo} />, | ||
<Resource | ||
name="comments" | ||
key="comments" | ||
list={Foo} | ||
/>, | ||
]) | ||
} | ||
</CoreAdmin> | ||
); | ||
render(<App />); | ||
await screen.findByText('Foo'); | ||
}); | ||
it('should accept a function returning a promise for a fragment of Resources as children', async () => { | ||
const Foo = () => <div>Foo</div>; | ||
const App = () => ( | ||
<CoreAdmin> | ||
{() => | ||
Promise.resolve( | ||
<> | ||
<Resource name="posts" list={Foo} /> | ||
<Resource name="comments" list={Foo} /> | ||
</> | ||
) | ||
} | ||
</CoreAdmin> | ||
); | ||
render(<App />); | ||
await screen.findByText('Foo'); | ||
}); | ||
}); | ||
}); |
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