Skip to content

Commit 92fca4c

Browse files
committed
Add Test to minimaly verify nullness handling in ReactComponents
1 parent fd0814a commit 92fca4c

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

tests/Feliz/Basic.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,13 @@ module RecordTypeInputTesting =
229229
]
230230
)
231231
]
232+
233+
module NullnessTesting =
234+
235+
[<ReactComponent>]
236+
let NullishPropComponent (maybeText: string | null) =
237+
Html.div [
238+
match maybeText with
239+
| null -> Html.h1 [ prop.testId "no-text"; prop.text "No text provided." ]
240+
| text -> Html.h1 [ prop.testId "has-text"; prop.text text ]
241+
]

tests/Feliz/Basic.test.fs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,24 @@ describe "Props Aliasing Tests #687" <| fun _ ->
264264

265265
let c = RTL.screen.getByTestId "props-aliasing"
266266
expect(c).toBeInTheDocument()
267+
268+
describe "Nullness Tests" <| fun _ ->
269+
270+
test "Component with nullable prop handles null correctly" <| fun _ ->
271+
RTL.render(
272+
NullnessTesting.NullishPropComponent(null)
273+
) |> ignore
274+
275+
let noText = RTL.screen.getByTestId "no-text"
276+
expect(noText).toBeInTheDocument()
277+
expect(noText).toHaveTextContent("No text provided.")
278+
279+
test "Component with nullable prop handles non-null correctly" <| fun _ ->
280+
281+
RTL.render(
282+
NullnessTesting.NullishPropComponent("Hello, Nullable!")
283+
) |> ignore
284+
285+
let hasText = RTL.screen.getByTestId "has-text"
286+
expect(hasText).toBeInTheDocument()
287+
expect(hasText).toHaveTextContent("Hello, Nullable!")

0 commit comments

Comments
 (0)