| 1 |
import { test } from 'uvu'; |
| 2 |
import * as assert from 'uvu/assert'; |
| 3 |
import * as ENV from './setup/env'; |
| 4 |
|
| 5 |
// Relies on `setup/register` |
| 6 |
import Count from '../src/Count.svelte'; |
| 7 |
|
| 8 |
test.before(ENV.setup); |
| 9 |
test.before.each(ENV.reset); |
| 10 |
|
| 11 |
test('should render with "5" by default', () => { |
| 12 |
const { container } = ENV.render(Count); |
| 13 |
|
| 14 |
assert.snapshot( |
| 15 |
container.innerHTML, |
| 16 |
`<button id="decr">--</button> <span>5</span> <button id="incr">++</button>` |
| 17 |
); |
| 18 |
}); |
| 19 |
|
| 20 |
test('should accept custom `count` prop', () => { |
| 21 |
const { container } = ENV.render(Count, { count: 99 }); |
| 22 |
|
| 23 |
assert.snapshot( |
| 24 |
container.innerHTML, |
| 25 |
`<button id="decr">--</button> <span>99</span> <button id="incr">++</button>` |
| 26 |
); |
| 27 |
}); |
| 28 |
|
| 29 |
test('should increment count after `button#incr` click', async () => { |
| 30 |
const { container } = ENV.render(Count); |
| 31 |
|
| 32 |
assert.snapshot( |
| 33 |
container.innerHTML, |
| 34 |
`<button id="decr">--</button> <span>5</span> <button id="incr">++</button>` |
| 35 |
); |
| 36 |
|
| 37 |
await ENV.fire( |
| 38 |
container.querySelector('#incr'), |
| 39 |
'click' |
| 40 |
); |
| 41 |
|
| 42 |
assert.snapshot( |
| 43 |
container.innerHTML, |
| 44 |
`<button id="decr">--</button> <span>6</span> <button id="incr">++</button>` |
| 45 |
); |
| 46 |
}); |
| 47 |
|
| 48 |
test('should decrement count after `button#decr` click', async () => { |
| 49 |
const { container } = ENV.render(Count); |
| 50 |
|
| 51 |
assert.snapshot( |
| 52 |
container.innerHTML, |
| 53 |
`<button id="decr">--</button> <span>5</span> <button id="incr">++</button>` |
| 54 |
); |
| 55 |
|
| 56 |
await ENV.fire( |
| 57 |
container.querySelector('#decr'), |
| 58 |
'click' |
| 59 |
); |
| 60 |
|
| 61 |
assert.snapshot( |
| 62 |
container.innerHTML, |
| 63 |
`<button id="decr">--</button> <span>4</span> <button id="incr">++</button>` |
| 64 |
); |
| 65 |
}); |
| 66 |
|
| 67 |
test.run(); |