-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-account.test.js
48 lines (39 loc) · 1.75 KB
/
create-account.test.js
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
41
42
43
44
45
46
47
48
import { screen, fireEvent } from '@testing-library/dom';
import '@testing-library/jest-dom/extend-expect'; // Import this to enhance expect assertions
import { validateForm } from './create-account.js'; // Adjust the import path
describe('validateForm function', () => {
it('displays error message if any field is empty', () => {
document.body.innerHTML = `
${require('./create-account.html')}
`;
const result = validateForm();
const errorMessage = screen.getByTestId('error-message'); // Adjust the test ID
expect(result).toBe(false);
expect(errorMessage).toBeInTheDocument();
});
it('displays error message if email and retypeEmail do not match', () => {
document.body.innerHTML = `
${require('./create-account.html')}
<input id="email" value="[email protected]" />
<input id="retypeEmail" value="[email protected]" />
<!-- Add other necessary fields -->
`;
const result = validateForm();
const errorMessage = screen.getByTestId('error-message'); // Adjust the test ID
expect(result).toBe(false);
expect(errorMessage).toBeInTheDocument();
expect(errorMessage).toHaveTextContent('Email and Retype Email, Password and Retype Password must match.');
});
it('submits the form when all fields are valid', () => {
document.body.innerHTML = `
${require('./create-account.html')}
<input id="email" value="[email protected]" />
<input id="retypeEmail" value="[email protected]" />
<input id="password" value="password" />
<input id="retypePassword" value="password" />
<!-- Add other necessary fields -->
`;
const result = validateForm();
expect(result).toBe(true);
});
});