Skip to content

Commit 6d995a2

Browse files
author
Sebastian Schürmann
committed
test(component-my-circle): simplified tests
1 parent 82b2442 commit 6d995a2

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

eslint.config.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ module.exports = [
2424
document: 'readonly',
2525
process: 'readonly',
2626
console: 'readonly',
27-
Document: 'readonly'
27+
Document: 'readonly',
28+
ShadowRoot: 'readonly',
29+
SVGSVGElement: 'readonly',
30+
SVGCircleElement: 'readonly',
31+
Element: 'readonly'
2832
}
2933
},
3034
plugins: {

packages/component-my-circle/test/component.test.ts

+14-19
Original file line numberDiff line numberDiff line change
@@ -12,55 +12,50 @@ const componentPath = resolve(__dirname, '../src/my-circle.ts');
1212
describe('MyCircle Component', () => {
1313
let mountContext: MountContext;
1414

15+
let circleTag: Element;
16+
let shadowRoot: ShadowRoot;
17+
let svg: SVGSVGElement;
18+
let circleElement: SVGCircleElement;
19+
1520
beforeEach(async () => {
1621
const helper = new TestHelper();
1722
mountContext = await helper.compileAndMountAsScript('my-circle', componentPath);
23+
const { document } = mountContext;
24+
circleTag = document.querySelector('my-circle')!;
25+
shadowRoot = circleTag?.shadowRoot as ShadowRoot;
26+
svg = shadowRoot?.querySelector('svg') as SVGSVGElement;
27+
circleElement = svg?.querySelector('circle') as SVGCircleElement;
1828
});
1929

2030
afterEach(() => {
2131
mountContext.jsdom.window.close();
2232
});
2333

2434
it('should create a circle element', () => {
25-
const { document } = mountContext;
26-
const circle = document.querySelector('my-circle');
27-
assert.ok(circle, 'Circle element should exist');
28-
assert.strictEqual(circle?.tagName.toLowerCase(), 'my-circle');
35+
assert.ok(circleTag, 'Circle element should exist');
36+
assert.strictEqual(circleTag?.tagName.toLowerCase(), 'my-circle');
2937
});
3038

3139
it('should create a shadow root', () => {
32-
const { document } = mountContext;
33-
const circle = document.querySelector('my-circle');
34-
const shadowRoot = circle?.shadowRoot;
3540
assert.ok(shadowRoot, 'Shadow root should exist');
3641
});
3742

3843
it('should render an SVG circle', () => {
39-
const { document } = mountContext;
40-
const circle = document.querySelector('my-circle');
41-
const shadowRoot = circle?.shadowRoot;
42-
const svg = shadowRoot?.querySelector('svg');
43-
const circleElement = svg?.querySelector('circle');
44-
4544
assert.ok(svg, 'SVG element should exist');
4645
assert.ok(circleElement, 'Circle element should exist in SVG');
4746
});
4847

4948
it('should update circle color when attribute changes', async () => {
50-
const { document } = mountContext;
51-
const circle = document.querySelector('my-circle');
52-
const shadowRoot = circle?.shadowRoot;
53-
const svgCircle = shadowRoot?.querySelector('circle');
5449

5550
// Default color
5651
assert.strictEqual(
57-
svgCircle?.getAttribute('fill'),
52+
circleElement?.getAttribute('fill'),
5853
'red',
5954
'Default color should be red'
6055
);
6156

6257
// Change color
63-
circle?.setAttribute('color', 'blue');
58+
circleTag?.setAttribute('color', 'blue');
6459
await new Promise(resolve => setTimeout(resolve, 200));
6560

6661
const svgCircle2 = shadowRoot?.querySelector('circle');

0 commit comments

Comments
 (0)