-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
180 additions
and
265 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
62 changes: 13 additions & 49 deletions
62
packages/x-tree-view/src/internals/plugins/useTreeViewItems/useTreeViewItems.test.tsx
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 |
---|---|---|
@@ -1,60 +1,24 @@ | ||
import * as React from 'react'; | ||
import { expect } from 'chai'; | ||
import { createRenderer, ErrorBoundary } from '@mui-internal/test-utils'; | ||
import { RichTreeView } from '@mui/x-tree-view/RichTreeView'; | ||
import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView'; | ||
import { TreeItem } from '@mui/x-tree-view/TreeItem'; | ||
import { describeTreeView } from 'test/utils/tree-view/describeTreeView'; | ||
|
||
describe('useTreeViewItems', () => { | ||
const { render } = createRenderer(); | ||
|
||
it('should throw an error when two items have the same ID (items prop approach)', function test() { | ||
// TODO is this fixed? | ||
if (!/jsdom/.test(window.navigator.userAgent)) { | ||
// can't catch render errors in the browser for unknown reason | ||
// tried try-catch + error boundary + window onError preventDefault | ||
this.skip(); | ||
} | ||
|
||
expect(() => | ||
render( | ||
<ErrorBoundary> | ||
<RichTreeView | ||
items={[ | ||
{ id: '1', label: '1' }, | ||
{ id: '1', label: 'B' }, | ||
]} | ||
/> | ||
</ErrorBoundary>, | ||
), | ||
).toErrorDev([ | ||
'MUI X: The Tree View component requires all items to have a unique `id` property.', | ||
'MUI X: The Tree View component requires all items to have a unique `id` property.', | ||
'The above error occurred in the <ForwardRef(RichTreeView)> component:', | ||
]); | ||
}); | ||
|
||
it('should throw an error when two items have the same ID (JSX approach)', function test() { | ||
describeTreeView('useTreeViewItems plugin', ({ render, treeViewComponent }) => { | ||
it('should throw an error when two items have the same ID', function test() { | ||
// TODO is this fixed? | ||
if (!/jsdom/.test(window.navigator.userAgent)) { | ||
// can't catch render errors in the browser for unknown reason | ||
// tried try-catch + error boundary + window onError preventDefault | ||
this.skip(); | ||
} | ||
|
||
expect(() => | ||
render( | ||
<ErrorBoundary> | ||
<SimpleTreeView> | ||
<TreeItem itemId="1" label="A" /> | ||
<TreeItem itemId="1" label="B" /> | ||
</SimpleTreeView> | ||
</ErrorBoundary>, | ||
), | ||
).toErrorDev([ | ||
'MUI X: The Tree View component requires all items to have a unique `id` property.', | ||
'MUI X: The Tree View component requires all items to have a unique `id` property.', | ||
'The above error occurred in the <ForwardRef(SimpleTreeView)> component:', | ||
]); | ||
expect(() => render({ items: [{ id: '1' }, { id: '1' }], withErrorBoundary: true })).toErrorDev( | ||
[ | ||
...(treeViewComponent === 'SimpleTreeView' | ||
? ['Encountered two children with the same key'] | ||
: []), | ||
'MUI X: The Tree View component requires all items to have a unique `id` property.', | ||
'MUI X: The Tree View component requires all items to have a unique `id` property.', | ||
`The above error occurred in the <ForwardRef(${treeViewComponent})> component`, | ||
], | ||
); | ||
}); | ||
}); |
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
Oops, something went wrong.