test.app.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import App from '../src/App.svelte'
  2. import { fireEvent, waitForElement } from '@testing-library/dom'
  3. import { render, cleanup } from '@testing-library/svelte'
  4. import '@testing-library/jest-dom/extend-expect'
  5. beforeEach(cleanup)
  6. describe('App', () => {
  7. test('should render greeting', () => {
  8. const { getByText } = render(App, { props: {name: "world"}})
  9. expect(getByText('Hello world!'))
  10. })
  11. test('two plus two', () => {
  12. const value = 2 + 2;
  13. expect(value).toBeGreaterThan(3);
  14. expect(value).toBeGreaterThanOrEqual(3.5);
  15. expect(value).toBeLessThan(5);
  16. expect(value).toBeLessThanOrEqual(4.5);
  17. // toBe and toEqual are equivalent for numbers
  18. expect(value).toBe(4);
  19. expect(value).toEqual(4);
  20. })
  21. test('should change button text after click', async () => {
  22. const { getByText } = render(App, { props: { name: 'world' } })
  23. fireEvent.click(getByText('Clicked 0 times'))
  24. const button = await waitForElement(() => getByText('Clicked 1 time'))
  25. expect(button).toBeInTheDocument()
  26. })
  27. })