@@ -12,55 +12,50 @@ const componentPath = resolve(__dirname, '../src/my-circle.ts');
12
12
describe ( 'MyCircle Component' , ( ) => {
13
13
let mountContext : MountContext ;
14
14
15
+ let circleTag : Element ;
16
+ let shadowRoot : ShadowRoot ;
17
+ let svg : SVGSVGElement ;
18
+ let circleElement : SVGCircleElement ;
19
+
15
20
beforeEach ( async ( ) => {
16
21
const helper = new TestHelper ( ) ;
17
22
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 ;
18
28
} ) ;
19
29
20
30
afterEach ( ( ) => {
21
31
mountContext . jsdom . window . close ( ) ;
22
32
} ) ;
23
33
24
34
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' ) ;
29
37
} ) ;
30
38
31
39
it ( 'should create a shadow root' , ( ) => {
32
- const { document } = mountContext ;
33
- const circle = document . querySelector ( 'my-circle' ) ;
34
- const shadowRoot = circle ?. shadowRoot ;
35
40
assert . ok ( shadowRoot , 'Shadow root should exist' ) ;
36
41
} ) ;
37
42
38
43
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
-
45
44
assert . ok ( svg , 'SVG element should exist' ) ;
46
45
assert . ok ( circleElement , 'Circle element should exist in SVG' ) ;
47
46
} ) ;
48
47
49
48
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' ) ;
54
49
55
50
// Default color
56
51
assert . strictEqual (
57
- svgCircle ?. getAttribute ( 'fill' ) ,
52
+ circleElement ?. getAttribute ( 'fill' ) ,
58
53
'red' ,
59
54
'Default color should be red'
60
55
) ;
61
56
62
57
// Change color
63
- circle ?. setAttribute ( 'color' , 'blue' ) ;
58
+ circleTag ?. setAttribute ( 'color' , 'blue' ) ;
64
59
await new Promise ( resolve => setTimeout ( resolve , 200 ) ) ;
65
60
66
61
const svgCircle2 = shadowRoot ?. querySelector ( 'circle' ) ;
0 commit comments