@@ -12,10 +12,16 @@ describe('useDisclosure()', () => {
1212 expect ( typeof result . current . onToggle ) . toBe ( 'function' ) ;
1313 } ) ;
1414
15+ describe ( 'with no default value' , ( ) => {
16+ it ( 'should return isOpen with false when nothing is passed as argument' , ( ) => {
17+ const { result } = renderHook ( ( ) => useDisclosure ( ) ) ;
18+ expect ( result . current . isOpen ) . toBe ( false ) ;
19+ } ) ;
20+ } ) ;
1521
1622 describe ( 'with default value' , ( ) => {
17- describe ( 'with correct default value as boolean ' , ( ) => {
18- describe ( 'should work with default value' , ( ) => {
23+ describe ( 'with correct default value' , ( ) => {
24+ describe ( 'with default value is a boolean ' , ( ) => {
1925 it ( 'should return isOpen with true' , ( ) => {
2026 const { result } = renderHook ( ( ) => useDisclosure ( true ) ) ;
2127 expect ( result . current . isOpen ) . toBe ( true ) ;
@@ -24,20 +30,39 @@ describe('useDisclosure()', () => {
2430 const { result } = renderHook ( ( ) => useDisclosure ( false ) ) ;
2531 expect ( result . current . isOpen ) . toBe ( false ) ;
2632 } ) ;
27- it ( 'should return isOpen with false when nothing is passed as argument' , ( ) => {
28- const { result } = renderHook ( ( ) => useDisclosure ( ) ) ;
33+ } ) ;
34+
35+ describe ( 'with default value is function' , ( ) => {
36+ it ( 'should return isOpen with true' , ( ) => {
37+ const { result } = renderHook ( ( ) => useDisclosure ( ( ) => true ) ) ;
38+ expect ( result . current . isOpen ) . toBe ( true ) ;
39+ } ) ;
40+ it ( 'should return isOpen with false' , ( ) => {
41+ const { result } = renderHook ( ( ) => useDisclosure ( ( ) => false ) ) ;
2942 expect ( result . current . isOpen ) . toBe ( false ) ;
3043 } ) ;
3144 } ) ;
3245 } ) ;
3346 describe ( 'with incorrect default value type' , ( ) => {
34- it ( 'should throw an error' , ( ) => {
35- const nonBoolean = '' as never ;
36- vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => vi . fn ( ) ) ;
37- expect ( ( ) => {
38- renderHook ( ( ) => useDisclosure ( nonBoolean ) ) ;
39- } ) . toThrowError ( 'defaultValue must be a boolean value' ) ;
40- vi . resetAllMocks ( ) ;
47+ describe ( 'with default value is a boolean' , ( ) => {
48+ it ( 'should throw an error' , ( ) => {
49+ const nonBoolean = '' as never ;
50+ vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => vi . fn ( ) ) ;
51+ expect ( ( ) => {
52+ renderHook ( ( ) => useDisclosure ( nonBoolean ) ) ;
53+ } ) . toThrowError ( 'defaultValue must be a boolean value' ) ;
54+ vi . resetAllMocks ( ) ;
55+ } ) ;
56+ } ) ;
57+ describe ( 'with default value is a function' , ( ) => {
58+ it ( 'should throw an error' , ( ) => {
59+ const nonBoolean = ( ) => '' as never ;
60+ vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => vi . fn ( ) ) ;
61+ expect ( ( ) => {
62+ renderHook ( ( ) => useDisclosure ( nonBoolean ) ) ;
63+ } ) . toThrowError ( 'defaultValue must be a boolean value' ) ;
64+ vi . resetAllMocks ( ) ;
65+ } ) ;
4166 } ) ;
4267 } ) ;
4368 } ) ;
0 commit comments