-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathindex.test.js
More file actions
40 lines (37 loc) · 1.44 KB
/
index.test.js
File metadata and controls
40 lines (37 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* Copyright (c) 2024, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import React from 'react'
import {screen} from '@testing-library/react'
import {renderWithProviders} from '@salesforce/retail-react-app/app/utils/test-utils'
import PasswordlessEmailConfirmation from '@salesforce/retail-react-app/app/components/email-confirmation/index'
import {useForm} from 'react-hook-form'
const WrapperComponent = ({...props}) => {
const form = useForm()
return <PasswordlessEmailConfirmation form={form} {...props} />
}
test('renders PasswordlessEmailConfirmation component with passed email', () => {
const email = 'test@salesforce.com'
renderWithProviders(<WrapperComponent email={email} />)
expect(screen.getByText(email)).toBeInTheDocument()
})
test('displays error message when form has global error', () => {
const WrapperWithError = () => {
const form = useForm()
const formWithError = {
...form,
formState: {
...form.formState,
errors: {
global: {message: 'test error'}
}
}
}
return <PasswordlessEmailConfirmation form={formWithError} />
}
renderWithProviders(<WrapperWithError />)
expect(screen.getByText('test error')).toBeInTheDocument()
})