Files
introduction-to-testing/examples/element-factory/src/button.test.js
2024-10-02 15:38:54 -05:00

27 lines
747 B
JavaScript

import { screen, fireEvent } from '@testing-library/dom';
import userEvent from '@testing-library/user-event';
import { createButton } from './button.js';
describe('createButton', () => {
beforeEach(() => {
document.innerHTML = '';
});
it.skip('should create a button element', () => {
document.body.appendChild(createButton());
const button = screen.getByRole('button', { name: 'Click Me' });
expect(button).toBeInTheDocument();
});
it('should change the text to "Clicked!" when clicked', async () => {
document.body.appendChild(createButton());
const button = screen.getByRole('button', { name: 'Click Me' });
await userEvent.click(button);
expect(button.textContent).toBe('Clicked!');
});
});