1234567891011121314151617181920212223242526272829303132333435363738 |
- import App from '../src/App.svelte'
- import { fireEvent, waitForElement } from '@testing-library/dom'
- import { render, cleanup } from '@testing-library/svelte'
- import '@testing-library/jest-dom/extend-expect'
- beforeEach(cleanup)
- describe('App', () => {
- test('should render greeting', () => {
- const { getByText } = render(App, { props: {name: "world"}})
- expect(getByText('Hello world!'))
- })
- test('two plus two', () => {
- const value = 2 + 2;
- expect(value).toBeGreaterThan(3);
- expect(value).toBeGreaterThanOrEqual(3.5);
- expect(value).toBeLessThan(5);
- expect(value).toBeLessThanOrEqual(4.5);
- // toBe and toEqual are equivalent for numbers
- expect(value).toBe(4);
- expect(value).toEqual(4);
- })
- test('should change button text after click', async () => {
- const { getByText } = render(App, { props: { name: 'world' } })
- fireEvent.click(getByText('Clicked 0 times'))
- const button = await waitForElement(() => getByText('Clicked 1 time'))
- expect(button).toBeInTheDocument()
- })
- })
|