Skip to content

Commit

Permalink
handling of undefined, as @navikt/fnrvalidator does not support it
Browse files Browse the repository at this point in the history
  • Loading branch information
langz committed Oct 8, 2024
1 parent 2892d92 commit 1ac5556
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function NationalIdentityNumber(props: Props) {

const fnrValidator = useCallback(
(value: string) => {
if (fnr(value).status === 'invalid') {
// have to check for undefined as @navikt/fnrvalidator does not support undefined
if (value === undefined || fnr(value).status === 'invalid') {
return Error(errorFnr)
}
},
Expand All @@ -55,7 +56,8 @@ function NationalIdentityNumber(props: Props) {

const dnrValidator = useCallback(
(value: string) => {
if (dnr(value).status === 'invalid') {
// have to check for undefined as @navikt/fnrvalidator does not support undefined
if (value === undefined || dnr(value).status === 'invalid') {
return Error(errorDnr)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ describe('Field.NationalIdentityNumber', () => {
rerender(<Field.NationalIdentityNumber validateInitially />)

await waitFor(() => {
expect(screen.queryByRole('alert')).not.toBeInTheDocument()
expect(screen.queryByRole('alert')).toBeInTheDocument()
expect(screen.queryByRole('alert')).toHaveTextContent(
nb.NationalIdentityNumber.errorFnr
)
})
})

Expand Down

0 comments on commit 1ac5556

Please sign in to comment.