Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleanup more tests #11738

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { assert_ok, test } from '../../test';

export default test({
Expand All @@ -12,11 +13,12 @@ export default test({
};
},

async test(assert, target, _, component, window) {
test(assert, target, _, component, window) {
const input = target.querySelector('input');
assert_ok(input);
input.value = 'everybody';
await input.dispatchEvent(new window.Event('input'));
input.dispatchEvent(new window.Event('input'));
flushSync();

assert.equal(component.name, 'everybody');
assert.htmlEqual(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { assert_ok, test } from '../../test';

export default test({
Expand All @@ -16,7 +17,8 @@ export default test({
async test(assert, target, _, component, window) {
const button = target.querySelector('button');
assert_ok(button);
await button.dispatchEvent(new window.MouseEvent('click', { bubbles: true }));
button.dispatchEvent(new window.MouseEvent('click', { bubbles: true }));
flushSync();

assert.ok(component.clicked);
assert.htmlEqual(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../assert';
const tick = () => Promise.resolve();

Expand All @@ -18,7 +19,8 @@ export default test({
assert.equal(p.innerHTML, 'Context works');
assert.equal(getComputedStyle(button).color, 'rgb(255, 0, 0)');

await button.dispatchEvent(new MouseEvent('click', { bubbles: true }));
button.dispatchEvent(new MouseEvent('click', { bubbles: true }));
flushSync();

assert.equal(el.counter.count, 1);
assert.equal(button.innerHTML, 'count: 1');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../assert';
const tick = () => Promise.resolve();

Expand All @@ -6,15 +7,18 @@ export default test({
const element = document.createElement('custom-element');
target.appendChild(element);
await tick();
flushSync();

/** @type {any} */
const el = target.querySelector('custom-element');
el.shadowRoot.querySelector('button').click();
await tick();
flushSync();

assert.equal(el.getAttribute('aria-expanded'), '');
el.shadowRoot.querySelector('button').click();
await tick();
flushSync();

assert.equal(el.getAttribute('aria-expanded'), null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../assert';
const tick = () => Promise.resolve();

Expand All @@ -23,6 +24,7 @@ export default test({
assert.equal(getComputedStyle(inner_p).color, 'rgb(255, 255, 255)');

button.click();
flushSync();
await tick();
await tick();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';

export default test({
html: `
<button>action</button>
`,

async test({ assert, target, window }) {
test({ assert, target, window }) {
const button = target.querySelector('button');
ok(button);

const enter = new window.MouseEvent('mouseenter');
const leave = new window.MouseEvent('mouseleave');
const ctrlPress = new window.KeyboardEvent('keydown', { ctrlKey: true });

await button.dispatchEvent(enter);
button.dispatchEvent(enter);
flushSync();
assert.htmlEqual(
target.innerHTML,
`
Expand All @@ -22,7 +24,8 @@ export default test({
`
);

await window.dispatchEvent(ctrlPress);
window.dispatchEvent(ctrlPress);
flushSync();
assert.htmlEqual(
target.innerHTML,
`
Expand All @@ -31,7 +34,8 @@ export default test({
`
);

await button.dispatchEvent(leave);
button.dispatchEvent(leave);
flushSync();
assert.htmlEqual(
target.innerHTML,
`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';

/** @type {string[]} */
Expand All @@ -9,14 +10,15 @@ export default test({
return { value };
},

async test({ assert, target, window }) {
test({ assert, target, window }) {
const inputs = target.querySelectorAll('input');

const event = new window.Event('input');
const event = new window.Event('input', { bubbles: true });

for (const input of inputs) {
input.value = 'h';
await input.dispatchEvent(event);
input.dispatchEvent(event);
flushSync();
}

// Svelte 5 breaking change, use:action now fires
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';

export default test({
Expand All @@ -15,13 +16,14 @@ export default test({
<p></p>
`,

async test({ assert, target, window }) {
test({ assert, target, window }) {
const input = target.querySelector('input');
ok(input);

const event = new window.Event('input');
input.value = 'h';
await input.dispatchEvent(event);
input.dispatchEvent(event);
flushSync();

assert.equal(input.value, 'H');
assert.htmlEqual(
Expand All @@ -33,7 +35,8 @@ export default test({
);

input.value = 'he';
await input.dispatchEvent(event);
input.dispatchEvent(event);
flushSync();
assert.equal(input.value, 'HE');
assert.htmlEqual(
target.innerHTML,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';

export default test({
Expand All @@ -17,8 +18,8 @@ export default test({
const change = new window.Event('change');

options[1].selected = true;
await select.dispatchEvent(change);
await Promise.resolve();
select.dispatchEvent(change);
flushSync();

assert.equal(span.textContent, 'b');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';

export default test({
Expand All @@ -13,15 +14,16 @@ export default test({
</select>
`,

async test({ assert, component, target, window }) {
test({ assert, component, target, window }) {
const select = target.querySelector('select');
ok(select);
const options = target.querySelectorAll('option');

const change = new window.Event('change');

options[1].selected = true;
await select.dispatchEvent(change);
select.dispatchEvent(change);
flushSync();

assert.equal(component.selected.letter, 'B');
assert.htmlEqual(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';

export default test({
Expand Down Expand Up @@ -25,17 +26,17 @@ export default test({
</div>
`,

async test({ assert, component, target, window }) {
test({ assert, component, target, window }) {
const inputs = [...target.querySelectorAll('input')];

const event = new window.Event('change');

inputs[1].checked = true;
await inputs[1].dispatchEvent(event);
inputs[1].dispatchEvent(event);
flushSync();

await component.clear();

await Promise.resolve();
component.clear();
flushSync();

assert.htmlEqual(
target.innerHTML,
Expand All @@ -46,9 +47,10 @@ export default test({
);

inputs[2].checked = true;
await inputs[2].dispatchEvent(event);

await component.clear();
inputs[2].dispatchEvent(event);
flushSync();
component.clear();
flushSync();

assert.htmlEqual(
target.innerHTML,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';

export default test({
Expand Down Expand Up @@ -37,7 +38,7 @@ export default test({
<p>1 completed</p>
`,

async test({ assert, component, target, window }) {
test({ assert, component, target, window }) {
const inputs = [...target.querySelectorAll('input')];

assert.ok(inputs[0].checked);
Expand All @@ -47,9 +48,8 @@ export default test({
const event = new window.Event('change');

inputs[1].checked = true;
await inputs[1].dispatchEvent(event);
// Wait for the DOM to update
await Promise.resolve();
inputs[1].dispatchEvent(event);
flushSync();

assert.equal(component.numCompleted, 2);
assert.htmlEqual(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';

const values = [{ name: 'Alpha' }, { name: 'Beta' }, { name: 'Gamma' }];
Expand Down Expand Up @@ -37,7 +38,7 @@ export default test({

<p>Beta</p>`,

async test({ assert, component, target, window }) {
test({ assert, component, target, window }) {
const inputs = target.querySelectorAll('input');
assert.equal(inputs[0].checked, false);
assert.equal(inputs[1].checked, true);
Expand All @@ -46,7 +47,8 @@ export default test({
const event = new window.Event('change');

inputs[0].checked = true;
await inputs[0].dispatchEvent(event);
inputs[0].dispatchEvent(event);
flushSync();

assert.htmlEqual(
target.innerHTML,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { test } from '../../test';

const values = [{ name: 'Alpha' }, { name: 'Beta' }, { name: 'Gamma' }];
Expand Down Expand Up @@ -37,7 +38,7 @@ export default test({

<p>Beta</p>`,

async test({ assert, component, target, window }) {
test({ assert, component, target, window }) {
let inputs = target.querySelectorAll('input');
assert.equal(inputs[0].checked, false);
assert.equal(inputs[1].checked, true);
Expand All @@ -46,7 +47,8 @@ export default test({
const event = new window.Event('change');

inputs[0].checked = true;
await inputs[0].dispatchEvent(event);
inputs[0].dispatchEvent(event);
flushSync();

assert.htmlEqual(
target.innerHTML,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';

export default test({
Expand All @@ -15,7 +16,7 @@ export default test({
<p>true</p>
`,

async test({ assert, component, target, window }) {
test({ assert, component, target, window }) {
const input = target.querySelector('input');
ok(input);

Expand All @@ -24,7 +25,8 @@ export default test({
const event = new window.Event('change');

input.checked = false;
await input.dispatchEvent(event);
input.dispatchEvent(event);
flushSync();

assert.htmlEqual(
target.innerHTML,
Expand Down
Loading
Loading