chore: improve test cases (#14984)

* chore: improve test cases

* lint
pull/14970/head
Dominic Gannaway 3 days ago committed by GitHub
parent ab3290fa87
commit 36ef59df1f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../assert';
const tick = () => Promise.resolve();
@ -14,8 +15,7 @@ export default test({
el.setAttribute('camel-case', 'universe');
el.setAttribute('an-array', '[3,4]');
el.setAttribute('camelcase2', 'Hi');
await tick();
await tick();
flushSync();
assert.htmlEqual(el.shadowRoot.innerHTML, '<h1>Hi universe!</h1> <p>3</p><p>4</p>');
assert.htmlEqual(
target.innerHTML,
@ -25,8 +25,7 @@ export default test({
el.camelCase = 'galaxy';
el.camelCase2 = 'Hey';
el.anArray = [5, 6];
await tick();
await tick();
flushSync();
assert.htmlEqual(el.shadowRoot.innerHTML, '<h1>Hey galaxy!</h1> <p>5</p><p>6</p>');
assert.htmlEqual(
target.innerHTML,

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../assert';
const tick = () => Promise.resolve();
@ -8,7 +9,8 @@ export default test({
/** @type {any} */
const el = target.querySelector('custom-element');
await el.updateFoo(42);
el.updateFoo(42);
flushSync();
const p = el.shadowRoot.querySelector('p');
assert.equal(p.textContent, '42');

@ -1,4 +1,5 @@
import { test } from '../../assert';
import { flushSync } from 'svelte';
const tick = () => Promise.resolve();
export default test({
@ -16,7 +17,7 @@ export default test({
assert.equal(p.innerHTML, 'false');
button.click();
await tick();
flushSync();
assert.equal(button.innerHTML, '1');
assert.equal(p.innerHTML, 'false');

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
@ -10,12 +11,13 @@ export default test({
<p>second: </p>
`,
async test({ assert, component, target, window }) {
test({ assert, component, target, window }) {
const event = new window.MouseEvent('click');
const buttons = target.querySelectorAll('button');
await buttons[1].dispatchEvent(event);
buttons[1].dispatchEvent(event);
flushSync();
assert.htmlEqual(
target.innerHTML,

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
@ -10,12 +11,13 @@ export default test({
<p>fromState: </p>
`,
async test({ assert, component, target, window }) {
test({ assert, component, target, window }) {
const event = new window.MouseEvent('click');
const buttons = target.querySelectorAll('button');
await buttons[1].dispatchEvent(event);
buttons[1].dispatchEvent(event);
flushSync();
assert.htmlEqual(
target.innerHTML,

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';
export default test({
@ -5,13 +6,14 @@ export default test({
html: '<button>10</button>',
async test({ assert, target, window }) {
test({ assert, target, window }) {
const event = new window.MouseEvent('click');
const button = target.querySelector('button');
ok(button);
await button.dispatchEvent(event);
button.dispatchEvent(event);
flushSync();
assert.htmlEqual(target.innerHTML, '<button>11</button>');
}

@ -1,9 +1,10 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';
export default test({
html: '<button>???</button>',
async test({ assert, target, window }) {
test({ assert, target, window }) {
const event = new window.MouseEvent('click', {
clientX: 42,
clientY: 42
@ -12,7 +13,8 @@ export default test({
const button = target.querySelector('button');
ok(button);
await button.dispatchEvent(event);
button.dispatchEvent(event);
flushSync();
assert.htmlEqual(target.innerHTML, '<button>42</button>');
}

@ -1,9 +1,10 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';
export default test({
html: '<button>0, 0</button>',
async test({ assert, target, window }) {
test({ assert, target, window }) {
const event = new window.MouseEvent('click', {
clientX: 42,
clientY: 42
@ -12,7 +13,8 @@ export default test({
const button = target.querySelector('button');
ok(button);
await button.dispatchEvent(event);
button.dispatchEvent(event);
flushSync();
assert.htmlEqual(target.innerHTML, '<button>42, 42</button>');
}

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';
export default test({
@ -8,7 +9,8 @@ export default test({
const click = new window.MouseEvent('click');
assert.htmlEqual(target.innerHTML, '<button>1</button>');
await button.dispatchEvent(click);
button.dispatchEvent(click);
flushSync();
assert.htmlEqual(target.innerHTML, '<button>2</button>');
}
});

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
@ -11,7 +12,9 @@ export default test({
const [b1] = target.querySelectorAll('button');
b1.click();
await Promise.resolve();
Promise.resolve();
flushSync();
assert.htmlEqual(
target.innerHTML,
`<button>2</button><button>3</button><button>4</button>\n-------\n<button>1</button>`

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
@ -11,6 +12,7 @@ export default test({
async test({ assert, component, target }) {
await (component.thePromise = Promise.resolve({ result: 1 }));
flushSync();
assert.htmlEqual(
target.innerHTML,
@ -21,6 +23,7 @@ export default test({
);
await new Promise((resolve) => setTimeout(resolve, 1));
flushSync();
assert.htmlEqual(
target.innerHTML,

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
@ -9,8 +10,9 @@ export default test({
<span>1</span>
`,
async test({ assert, component, target }) {
await component.list.update();
test({ assert, component, target }) {
component.list.update();
flushSync();
assert.htmlEqual(
target.innerHTML,

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';
export default test({
@ -18,7 +19,7 @@ export default test({
<p>hello</p>
`,
async test({ assert, component, target, window }) {
test({ assert, component, target, window }) {
assert.equal(component.name, 'world');
const el = target.querySelector('editor');
@ -27,7 +28,8 @@ export default test({
const event = new window.Event('input');
el.textContent = 'everybody';
await el.dispatchEvent(event);
el.dispatchEvent(event);
flushSync();
assert.htmlEqual(
target.innerHTML,

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';
export default test({
@ -10,7 +11,7 @@ export default test({
<p>hello world</p>
`,
async test({ assert, component, target, window }) {
test({ assert, component, target, window }) {
const el = target.querySelector('editor');
ok(el);
assert.equal(el.textContent, 'world');
@ -18,7 +19,8 @@ export default test({
const event = new window.Event('input');
el.textContent = 'everybody';
await el.dispatchEvent(event);
el.dispatchEvent(event);
flushSync();
assert.htmlEqual(
target.innerHTML,

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';
export default test({
@ -17,7 +18,7 @@ export default test({
<p>indeterminate? true</p>
`,
async test({ assert, component, target, window }) {
test({ assert, component, target, window }) {
const input = target.querySelector('input');
ok(input);
@ -28,7 +29,8 @@ export default test({
input.checked = true;
input.indeterminate = false;
await input.dispatchEvent(event);
input.dispatchEvent(event);
flushSync();
assert.equal(component.indeterminate, false);
assert.equal(component.checked, true);

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';
export default test({
@ -7,8 +8,9 @@ export default test({
return { letter: 'b' };
},
async test({ assert, component, target, window }) {
await component.modal.toggle();
test({ assert, component, target, window }) {
component.modal.toggle();
flushSync();
assert.htmlEqual(
target.innerHTML,
@ -28,7 +30,8 @@ export default test({
const change = new window.MouseEvent('change');
select.options[2].selected = true;
await select.dispatchEvent(change);
select.dispatchEvent(change);
flushSync();
assert.equal(component.letter, 'c');
assert.deepEqual(
@ -49,9 +52,9 @@ export default test({
`
);
await component.modal.toggle();
await component.modal.toggle();
await Promise.resolve();
component.modal.toggle();
component.modal.toggle();
flushSync();
select = target.querySelector('select');
ok(select);

@ -1,7 +1,8 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
async test({ assert, component }) {
test({ assert, component }) {
const { foo, p } = component;
/** @type {string[]} */
@ -13,7 +14,8 @@ export default test({
}
});
await foo.double();
foo.double();
flushSync();
assert.deepEqual(values, ['6']);
}

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
const data = {
@ -15,9 +16,10 @@ export default test({
html: '<p>hello</p>',
async test({ assert, component, target }) {
test({ assert, component, target }) {
data.message = 'goodbye';
await component.$set({ data });
component.$set({ data });
flushSync();
assert.htmlEqual(target.innerHTML, '<p>goodbye</p>');
}

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
@ -5,7 +6,7 @@ export default test({
<span slot="foo" class="1">1</span>
0
`,
async test({ assert, target, component, window }) {
test({ assert, target, component, window }) {
component.x = 2;
assert.htmlEqual(
@ -17,7 +18,8 @@ export default test({
);
const span = target.querySelector('span');
await span?.dispatchEvent(new window.MouseEvent('click', { bubbles: true }));
span?.dispatchEvent(new window.MouseEvent('click', { bubbles: true }));
flushSync();
assert.htmlEqual(
target.innerHTML,

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
@ -10,7 +11,7 @@ export default test({
async test({ component, assert, target }) {
await component.update();
await Promise.resolve();
flushSync();
assert.htmlEqual(
target.innerHTML,

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
@ -8,7 +9,8 @@ export default test({
`,
async test({ component, target, assert }) {
await component.update();
await Promise.resolve();
flushSync();
assert.htmlEqual(
target.innerHTML,
`

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
@ -10,7 +11,7 @@ export default test({
async test({ component, assert, target }) {
await component.update();
await Promise.resolve();
flushSync();
assert.htmlEqual(
target.innerHTML,

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
@ -10,9 +11,9 @@ export default test({
</ul>
`,
async test({ assert, component, target }) {
await component.swap(0, 1);
await Promise.resolve();
test({ assert, component, target }) {
component.swap(0, 1);
flushSync();
assert.htmlEqual(
target.innerHTML,

@ -1,19 +1,26 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
html: '<div>3</div>',
async test({ assert, component, target }) {
test({ assert, component, target }) {
const div = target.querySelector('div');
await component.mutate();
component.mutate();
flushSync();
assert.htmlEqual(target.innerHTML, '<div>5</div>');
assert.strictEqual(div, target.querySelector('div'));
await component.reassign();
component.reassign();
flushSync();
assert.htmlEqual(target.innerHTML, '<div>7</div>');
assert.strictEqual(div, target.querySelector('div'));
await component.changeKey();
component.changeKey();
flushSync();
assert.htmlEqual(target.innerHTML, '<div>7</div>');
assert.notStrictEqual(div, target.querySelector('div'));
}

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
@ -10,11 +11,12 @@ export default test({
<p>b: 2</p>
`,
async test({ assert, component, target }) {
await component.$set({
test({ assert, component, target }) {
component.$set({
a: 5,
b: 6
});
flushSync();
assert.htmlEqual(
target.innerHTML,

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
@ -11,8 +12,9 @@ export default test({
<p>c: 3</p>
`,
async test({ assert, component, target }) {
await component.$set({ a: 4 });
test({ assert, component, target }) {
component.$set({ a: 4 });
flushSync();
assert.htmlEqual(
target.innerHTML,
@ -23,7 +25,8 @@ export default test({
`
);
await component.$set({ b: 5 });
component.$set({ b: 5 });
flushSync();
assert.htmlEqual(
target.innerHTML,

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
import { store } from './store.js';
@ -6,10 +7,9 @@ export default test({
before_test() {
store.reset();
},
async test({ assert, target }) {
test({ assert, target }) {
store.set(42);
await Promise.resolve();
flushSync();
assert.htmlEqual(target.innerHTML, '<h1>42</h1>');

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
@ -6,29 +7,35 @@ export default test({
<p>42</p>
`,
async test({ assert, component, target }) {
await component.updateStore(undefined);
await Promise.resolve();
test({ assert, component, target }) {
component.updateStore(undefined);
flushSync();
assert.htmlEqual(target.innerHTML, '<p></p><p>42</p>');
await component.updateStore(33);
await Promise.resolve();
component.updateStore(33);
flushSync();
assert.htmlEqual(target.innerHTML, '<p>33</p><p>42</p>');
await component.updateStore(undefined);
await Promise.resolve();
component.updateStore(undefined);
flushSync();
assert.htmlEqual(target.innerHTML, '<p></p><p>42</p>');
await component.updateVar(undefined);
await Promise.resolve();
component.updateVar(undefined);
flushSync();
assert.htmlEqual(target.innerHTML, '<p></p><p></p>');
await component.updateVar(33);
await Promise.resolve();
component.updateVar(33);
flushSync();
assert.htmlEqual(target.innerHTML, '<p></p><p>33</p>');
await component.updateVar(undefined);
await Promise.resolve();
component.updateVar(undefined);
flushSync();
assert.htmlEqual(target.innerHTML, '<p></p><p></p>');
}
});

@ -1,10 +1,12 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
html: '1-2',
async test({ assert, component, target }) {
await component.update();
test({ assert, component, target }) {
component.update();
flushSync();
assert.htmlEqual(target.innerHTML, '3-4');
}

@ -1,5 +1,6 @@
import { test } from '../../test';
import { create_deferred } from '../../../helpers';
import { flushSync } from 'svelte';
/** @type {ReturnType<typeof create_deferred>} */
let deferred;
@ -17,6 +18,8 @@ export default test({
async test({ assert, target }) {
await deferred.promise;
flushSync();
assert.htmlEqual(
target.innerHTML,
`

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
@ -17,13 +18,14 @@ export default test({
<p>quux: core</p></div>
`,
async test({ assert, component, target }) {
await component.$set({
test({ assert, component, target }) {
component.$set({
foo: 'wut',
baz: 40 + 3,
qux: `this is a ${'rather boring'} string`,
quux: 'heart'
});
flushSync();
assert.htmlEqual(
target.innerHTML,

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
@ -6,10 +7,9 @@ export default test({
<div>Hello World</div>
`,
async test({ assert, component, target }) {
await component.update_value('Hi Svelte');
await Promise.resolve();
await Promise.resolve();
test({ assert, component, target }) {
component.update_value('Hi Svelte');
flushSync();
assert.htmlEqual(
target.innerHTML,

@ -1,10 +1,13 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
html: '0',
async test({ assert, component, target }) {
await component.increment();
test({ assert, component, target }) {
component.increment();
flushSync();
assert.htmlEqual(target.innerHTML, '1');
}
});

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
import { count } from './store.js';
@ -8,8 +9,9 @@ export default test({
count.set(0);
},
async test({ assert, component, target }) {
await component.increment();
test({ assert, component, target }) {
component.increment();
flushSync();
assert.htmlEqual(target.innerHTML, '<p>count: 1</p>');
}

@ -1,14 +1,16 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
html: '<p>escaped: false</p>',
async test({ assert, target, window }) {
test({ assert, target, window }) {
const event = new window.KeyboardEvent('keydown', {
key: 'Escape'
});
await window.dispatchEvent(event);
window.dispatchEvent(event);
flushSync();
assert.htmlEqual(
target.innerHTML,

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
@ -7,7 +8,7 @@ export default test({
async test({ assert, target }) {
await Promise.resolve();
await Promise.resolve();
flushSync();
assert.htmlEqual(
target.innerHTML,
'<div>d2: 3,4,5</div><div>d3: 3,4,5</div><div>d4: 3,4,5</div>'

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
@ -5,7 +6,7 @@ export default test({
// The test has a bunch of queueMicrotasks
await Promise.resolve();
await Promise.resolve();
await Promise.resolve();
flushSync();
assert.htmlEqual(target.innerHTML, `<div>Zeeba Neighba</div>`);
}

@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
@ -5,7 +6,7 @@ export default test({
async test({ assert, target }) {
await Promise.resolve();
await Promise.resolve();
flushSync();
assert.htmlEqual(target.innerHTML, `<span>1</span>`);
}
});

Loading…
Cancel
Save