-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TreeView] Throw an error when two items have the same id (#11715)
- Loading branch information
1 parent
25e8be7
commit 58c5fe8
Showing
3 changed files
with
84 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
60 changes: 60 additions & 0 deletions
60
packages/x-tree-view/src/internals/plugins/useTreeViewNodes/useTreeViewNodes.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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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'; | ||
|
||
describe('useTreeViewNodes', () => { | ||
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() { | ||
// 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 nodeId="1" label="A" /> | ||
<TreeItem nodeId="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:', | ||
]); | ||
}); | ||
}); |
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