Skip to content

Commit

Permalink
fix(Forms): ensure pathUndefined on Form.Visibility does render whe…
Browse files Browse the repository at this point in the history
…n value is `undefined`
  • Loading branch information
tujoworker committed Feb 5, 2025
1 parent c1c6db1 commit e2a11c0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ describe('useVisibility', () => {
)
expect(result.current.check()).toBe(true)
})

it('should return false when value exists but is "undefined"', () => {
const { result } = renderHook(useVisibility, {
wrapper: ({ children }) => (
<Provider data={{ isUndefined: undefined }}>{children}</Provider>
),
})
expect(
result.current.check({
pathUndefined: '/isUndefined',
})
).toBe(true)
})
})

describe('pathTruthy', () => {
Expand Down Expand Up @@ -725,6 +738,28 @@ describe('useVisibility', () => {
)
expect(result.current.check()).toBe(true)
})

it('should return true when value exists but is "undefined"', () => {
const { result } = renderHook(
() =>
useVisibility({
withinIterate: true,
pathUndefined: '/isUndefined',
}),
{
wrapper: ({ children }) => (
<Provider
data={{
myList: [{ isUndefined: undefined }],
}}
>
<Iterate.Array path="/myList">{children}</Iterate.Array>
</Provider>
),
}
)
expect(result.current.check()).toBe(true)
})
})

describe('pathTruthy', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ export default function useVisibility(props?: Partial<Props>) {
pathUndefined &&
pointer.has(data, makeLocalPath(pathUndefined))
) {
return false
return (
pointer.get(data, makeLocalPath(pathUndefined)) === undefined
)
}

const getValue = (path: Path) => {
Expand Down

0 comments on commit e2a11c0

Please sign in to comment.