-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react): add useLayer hook (#11654)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
524845d
commit 8a9c11e
Showing
8 changed files
with
145 additions
and
28 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
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
File renamed without changes.
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
64 changes: 64 additions & 0 deletions
64
packages/react/src/components/Layer/__tests__/useLayer-test.js
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,64 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2018 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { Layer, useLayer } from '../../Layer'; | ||
|
||
describe('useLayer', () => { | ||
test('default value', () => { | ||
const values = []; | ||
|
||
function TestComponent() { | ||
const value = useLayer(); | ||
values.push(value); | ||
return null; | ||
} | ||
|
||
render(<TestComponent />); | ||
|
||
expect(values).toEqual([ | ||
{ | ||
level: 1, | ||
}, | ||
]); | ||
}); | ||
|
||
test('nesting', () => { | ||
const values = []; | ||
|
||
function TestComponent() { | ||
const value = useLayer(); | ||
values.push(value); | ||
return null; | ||
} | ||
|
||
render( | ||
<> | ||
<TestComponent /> | ||
<Layer> | ||
<TestComponent /> | ||
<Layer> | ||
<TestComponent /> | ||
</Layer> | ||
</Layer> | ||
</> | ||
); | ||
|
||
expect(values).toEqual([ | ||
{ | ||
level: 1, | ||
}, | ||
{ | ||
level: 2, | ||
}, | ||
{ | ||
level: 2, | ||
}, | ||
]); | ||
}); | ||
}); |
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