Skip to content

Commit 8bc9587

Browse files
committed
test
1 parent 40e6908 commit 8bc9587

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { assertType } from 'vitest';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
mode: ['client'],
6+
7+
compileOptions: {
8+
dev: true
9+
},
10+
11+
test({ assert, target, warnings, logs }) {
12+
/** @type {any} */
13+
let error = null;
14+
15+
const handler = (/** @type {any} */ e) => {
16+
error = e.error;
17+
e.stopImmediatePropagation();
18+
};
19+
20+
window.addEventListener('error', handler, true);
21+
22+
const [b1, b2, b3] = target.querySelectorAll('button');
23+
24+
b1.click();
25+
assert.deepEqual(logs, []);
26+
assert.equal(error, null);
27+
28+
error = null;
29+
logs.length = 0;
30+
31+
b2.click();
32+
assert.deepEqual(logs, ['clicked']);
33+
assert.equal(error, null);
34+
35+
error = null;
36+
logs.length = 0;
37+
38+
b3.click();
39+
assert.deepEqual(logs, []);
40+
assert.deepEqual(warnings, [
41+
'`click` handler at main.svelte:10:17 should be a function. Did you mean to add a leading `() =>`?'
42+
]);
43+
assert.isNotNull(error);
44+
assert.match(error.message, /is not a function/);
45+
46+
window.removeEventListener('error', handler, true);
47+
}
48+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script>
2+
let ignore = null;
3+
let handler = () => console.log("clicked");
4+
let bad = "invalid";
5+
6+
</script>
7+
8+
<button onclick={ignore}>click</button>
9+
<button onclick={handler}>click</button>
10+
<button onclick={bad}>click</button>

0 commit comments

Comments
 (0)