Rename helper library to get-error-message

This commit is contained in:
Steve Kinney
2024-10-01 16:58:41 -05:00
parent 417bcb39c9
commit 75e9bb7ca7
13 changed files with 34 additions and 20 deletions

View File

@@ -0,0 +1,35 @@
import { screen } from '@testing-library/dom';
import userEvent from '@testing-library/user-event';
import { createSecretInput } from './secret-input.js';
import '@testing-library/jest-dom/vitest';
describe('createSecretInput', async () => {
beforeEach(() => {
vi.spyOn(localStorage, 'getItem').mockReturnValue('test secret');
vi.spyOn(localStorage, 'setItem');
document.body.innerHTML = '';
document.body.appendChild(createSecretInput());
});
afterEach(() => {
vi.restoreAllMocks();
});
it('should have loaded the secret from localStorage', async () => {
expect(screen.getByLabelText('Secret')).toHaveValue('test secret');
expect(localStorage.getItem).toHaveBeenCalledWith('secret');
});
it('should save the secret to localStorage', async () => {
const input = screen.getByLabelText('Secret');
const button = screen.getByText('Store Secret');
await userEvent.clear(input);
await userEvent.type(input, 'new secret');
await userEvent.click(button);
expect(localStorage.setItem).toHaveBeenCalledWith('secret', 'new secret');
});
});