1
1
import { slottable } from "./slottable" ;
2
2
import { render } from "@testing-library/react" ;
3
- import type { TSlottablePropsFactory } from "dist " ;
3
+ import type { TSlottablePropsFactory } from "./types " ;
4
4
import { describe , test , expect } from "vitest" ;
5
5
6
6
describe ( "slottable" , ( ) => {
7
7
test ( "should render children in specific slots" , ( ) => {
8
8
const Component = slottable < "div" , TSlottablePropsFactory < object > > (
9
9
( { children } ) => {
10
10
return < div > { children } </ div > ;
11
- } ,
11
+ }
12
12
) ;
13
13
const { getByText } = render (
14
14
< Component >
15
15
< div data-testid = "test-child" > Test child</ div >
16
- </ Component > ,
16
+ </ Component >
17
17
) ;
18
18
expect ( typeof Component ) . toBe ( "object" ) ; // slottable returns Exotic component
19
19
expect ( getByText ( "Test child" ) ) . toBeInTheDocument ( ) ;
@@ -24,8 +24,38 @@ describe("slottable", () => {
24
24
( { children } ) => {
25
25
return < div > { children } </ div > ;
26
26
} ,
27
- "TestComponent" ,
27
+ "TestComponent"
28
28
) ;
29
29
expect ( Component . displayName ) . toBe ( "TestComponent" ) ;
30
30
} ) ;
31
+
32
+ test ( "should accept undefined as a valid value for className prop" , ( ) => {
33
+ const Component = slottable < "div" , TSlottablePropsFactory < object > > (
34
+ ( { children } ) => {
35
+ return < div > { children } </ div > ;
36
+ }
37
+ ) ;
38
+ const { getByText } = render (
39
+ < Component className = { undefined } >
40
+ < div data-testid = "test-child" > Test child 1</ div >
41
+ </ Component >
42
+ ) ;
43
+ expect ( typeof Component ) . toBe ( "object" ) ; // slottable returns Exotic component
44
+ expect ( getByText ( "Test child 1" ) ) . toBeInTheDocument ( ) ;
45
+ } ) ;
46
+
47
+ test ( "should accept null as a valid value for className prop" , ( ) => {
48
+ const Component = slottable < "div" , TSlottablePropsFactory < object > > (
49
+ ( { children } ) => {
50
+ return < div > { children } </ div > ;
51
+ }
52
+ ) ;
53
+ const { getByText } = render (
54
+ < Component className = { null } >
55
+ < div data-testid = "test-child" > Test child 2</ div >
56
+ </ Component >
57
+ ) ;
58
+ expect ( typeof Component ) . toBe ( "object" ) ; // slottable returns Exotic component
59
+ expect ( getByText ( "Test child 2" ) ) . toBeInTheDocument ( ) ;
60
+ } ) ;
31
61
} ) ;
0 commit comments