Skip to content

Commit aa96149

Browse files
authored
test: Remove temporary commonjs module mocks (#1910)
No issue created, but noticed issue here ed0d489 ### Changes - Removes unused node module mocks and use commonjs plugin to import modules in tests - Fixes org form test after removing temporary stub
1 parent 192737e commit aa96149

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

frontend/src/__mocks__/color.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

frontend/src/__mocks__/slugify.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

frontend/src/pages/invite/ui/org-form.test.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, fixture, oneEvent } from "@open-wc/testing";
2-
import type { SlInput } from "@shoelace-style/shoelace";
2+
import { serialize, type SlInput } from "@shoelace-style/shoelace";
33
import { html } from "lit/static-html.js";
44
import { restore, stub } from "sinon";
55

@@ -65,15 +65,23 @@ describe("btrix-org-form", () => {
6565

6666
const form = el.shadowRoot!.querySelector<HTMLFormElement>("form")!;
6767

68-
form
69-
.querySelector('sl-input[name="orgName"]')
70-
?.setAttribute("value", "Fake Org Name");
71-
form
72-
.querySelector('sl-input[name="orgSlug"]')
73-
?.setAttribute("value", "fake-org-name");
68+
const orgName = form.querySelector<SlInput>('sl-input[name="orgName"]')!;
69+
const orgSlug = form.querySelector<SlInput>('sl-input[name="orgSlug"]')!;
70+
71+
orgName.setAttribute("value", "Fake Org Name");
72+
orgSlug.setAttribute("value", "fake-org-name");
73+
74+
await orgName.updateComplete;
75+
await orgSlug.updateComplete;
7476

7577
const listener = oneEvent(form, "submit");
7678

79+
// HACK Not completely sure why this works, but without calling `serialize`
80+
// the form will not be serialized in `org-form`.
81+
// Maybe due the implementation with `Reflect`?
82+
// https://github.com/shoelace-style/shoelace/blob/0aecf6959986817d9315df90c898da55a8a64290/src/utilities/form.ts#L12
83+
serialize(form);
84+
7785
form.requestSubmit();
7886

7987
await el.updateComplete;

frontend/web-test-runner.config.mjs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ export default {
4949
// web-test-runner expects es modules,
5050
// include umd/commonjs modules here:
5151
"node_modules/url-pattern/**/*",
52+
"node_modules/lodash/**/*",
53+
"node_modules/color/**/*",
54+
"node_modules/slugify/**/*",
5255
],
5356
}),
5457
importMapsPlugin({
@@ -65,12 +68,6 @@ export default {
6568
"@shoelace-style/shoelace/dist/themes/light.css": fileURLToPath(
6669
new URL("./src/__mocks__/_empty.js", import.meta.url),
6770
),
68-
color: fileURLToPath(
69-
new URL("./src/__mocks__/color.js", import.meta.url),
70-
),
71-
slugify: fileURLToPath(
72-
new URL("./src/__mocks__/slugify.js", import.meta.url),
73-
),
7471
},
7572
},
7673
},

0 commit comments

Comments
 (0)