Skip to content

Commit 9010a44

Browse files
committed
refactor: split test-utils/elements into separate module and test files
Separates test helper exports from their tests to follow standard conventions where .test.js files only contain tests. This fixes import resolution issues where tests couldn't find 'test-utils/elements'.
1 parent b0134f7 commit 9010a44

File tree

2 files changed

+49
-45
lines changed

2 files changed

+49
-45
lines changed

test-utils/elements.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
export const $anchor = (text = '0') => document.createComment(text);
2+
export const $text = (text) => document.createTextNode(text);
3+
export const $element = (text) => {
4+
const div = document.createElement('div');
5+
if(text !== undefined) div.textContent = text;
6+
return div;
7+
};
8+
export const $helloText = () => $text('Hello');
9+
10+
export function elementWithText(text = 'hello') {
11+
const dom = $element();
12+
dom.append($text(text));
13+
return { dom, anchor: null };
14+
}
15+
16+
export function elementWithTextAnchor() {
17+
const dom = $element();
18+
dom.append($helloText(), $anchor());
19+
return { dom, anchor: dom.lastChild };
20+
}
21+
22+
export function elementWithTextAnchorText() {
23+
const dom = $element();
24+
dom.append($helloText(), $anchor(), $helloText());
25+
return { dom, anchor: dom.firstChild.nextSibling };
26+
}
27+
28+
export function elementWithAnchor() {
29+
const dom = $element();
30+
dom.append($anchor());
31+
return { dom, anchor: dom.firstChild };
32+
}
33+
34+
export function elementWithAnchorText() {
35+
const dom = $element();
36+
dom.append($anchor(), $helloText());
37+
return { dom, anchor: dom.firstChild };
38+
}
39+
40+
export const elements = [
41+
elementWithTextAnchor,
42+
elementWithTextAnchorText,
43+
elementWithAnchor,
44+
elementWithAnchorText,
45+
];

test-utils/elements.test.js

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,20 @@
11
import { describe, test } from 'vitest';
2-
3-
export const elements = [
2+
import {
43
elementWithTextAnchor,
54
elementWithTextAnchorText,
65
elementWithAnchor,
76
elementWithAnchorText,
8-
];
9-
10-
export const $anchor = (text = '0') => document.createComment(text);
11-
export const $text = (text) => document.createTextNode(text);
12-
export const $element = (text) => {
13-
const div = document.createElement('div');
14-
if(text !== undefined) div.textContent = text;
15-
return div;
16-
};
17-
export const $helloText = () => $text('Hello');
18-
19-
export function elementWithText(text = 'hello') {
20-
const dom = $element();
21-
dom.append($text(text));
22-
return { dom, anchor: null };
23-
}
24-
25-
export function elementWithTextAnchor() {
26-
const dom = $element();
27-
dom.append($helloText(), $anchor());
28-
return { dom, anchor: dom.lastChild };
29-
}
30-
31-
export function elementWithTextAnchorText() {
32-
const dom = $element();
33-
dom.append($helloText(), $anchor(), $helloText());
34-
return { dom, anchor: dom.firstChild.nextSibling };
35-
}
36-
37-
export function elementWithAnchor() {
38-
const dom = $element();
39-
dom.append($anchor());
40-
return { dom, anchor: dom.firstChild };
41-
}
42-
43-
export function elementWithAnchorText() {
44-
const dom = $element();
45-
dom.append($anchor(), $helloText());
46-
return { dom, anchor: dom.firstChild };
47-
}
7+
} from './elements.js';
488

499
describe('test util elements', () => {
5010

5111
test('text-anchor', ({ expect }) => {
52-
expect(elementWithTextAnchorText()).toMatchInlineSnapshot(`
12+
expect(elementWithTextAnchor()).toMatchInlineSnapshot(`
5313
{
5414
"anchor": <!--0-->,
5515
"dom": <div>
5616
Hello
5717
<!--0-->
58-
Hello
5918
</div>,
6019
}
6120
`);
@@ -96,4 +55,4 @@ describe('test util elements', () => {
9655
}
9756
`);
9857
});
99-
});
58+
});

0 commit comments

Comments
 (0)