Oz Tiram 5 rokov pred
rodič
commit
0329e21621
2 zmenil súbory, kde vykonal 37 pridanie a 2 odobranie
  1. 11 1
      src/App.svelte
  2. 26 1
      tests/test.app.js

+ 11 - 1
src/App.svelte

@@ -1,5 +1,11 @@
 <script>
-  let name = 'world';
+  export let name;
+
+  let count = 0;
+
+  function handleClick() {
+	count += 1;
+  }
 </script>
 
 <style>
@@ -9,3 +15,7 @@
 </style>
 
 <h1>Hello {name}!</h1>
+
+<button on:click={handleClick}>
+	Clicked {count} {count === 1 ? 'time' : 'times'}
+</button>

+ 26 - 1
tests/test.app.js

@@ -3,8 +3,33 @@ import { render, cleanup } from '@testing-library/svelte'
 beforeEach(cleanup)
 describe('App', () => {
   test('should render greeting', () => {
-    const { getByText } = render(App, { props: {} })
+    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' } })
+    expect(getByText('Hello world!'))
+
+    fireEvent.click(getByText('Clicked 0 times'))
+
+    const button = await waitForElement(() => getByText('Clicked 1 times'))
+
+    expect(button).toBeInTheDocument()
+  })
+
 })
+
+