test.app.js 970 B

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