@@ -4,7 +4,7 @@ import { fixture, html, expect, fixtureCleanup, aTimeout } from '@open-wc/testin
4
4
import { ICustomElement } from '../dist' ;
5
5
import { CustomStateSet } from '../src/CustomStateSet' ;
6
6
7
- class CustomElementStateInConstructor extends HTMLElement {
7
+ class CustomElementAddStateInConstructor extends HTMLElement {
8
8
internals = this . attachInternals ( ) ;
9
9
constructor ( ) {
10
10
super ( ) ;
@@ -13,8 +13,20 @@ class CustomElementStateInConstructor extends HTMLElement {
13
13
}
14
14
}
15
15
16
- const tagName = 'custom-element-state-in-constructor'
17
- customElements . define ( tagName , CustomElementStateInConstructor ) ;
16
+ const addStateTagName = 'custom-element-add-state-in-constructor' ;
17
+ customElements . define ( addStateTagName , CustomElementAddStateInConstructor ) ;
18
+
19
+ class CustomElementDeleteStateInConstructor extends HTMLElement {
20
+ internals = this . attachInternals ( ) ;
21
+ constructor ( ) {
22
+ super ( ) ;
23
+
24
+ this . internals . states . delete ( '--foo' ) ;
25
+ }
26
+ }
27
+
28
+ const deleteStateTagName = 'custom-element-delete-state-in-constructor' ;
29
+ customElements . define ( deleteStateTagName , CustomElementDeleteStateInConstructor ) ;
18
30
19
31
describe ( 'CustomStateSet polyfill' , ( ) => {
20
32
let el : HTMLElement ;
@@ -74,7 +86,7 @@ describe('CustomStateSet polyfill', () => {
74
86
it ( 'will use a timeout if a state is added in a constructor' , async ( ) => {
75
87
let el ;
76
88
expect ( ( ) => {
77
- el = document . createElement ( tagName ) ;
89
+ el = document . createElement ( addStateTagName ) ;
78
90
} ) . not . to . throw ( ) ;
79
91
80
92
if ( window . CustomStateSet . isPolyfilled ) {
@@ -84,4 +96,18 @@ describe('CustomStateSet polyfill', () => {
84
96
expect ( el . matches ( `:--foo` ) ) . to . be . true ;
85
97
}
86
98
} ) ;
99
+
100
+ it ( 'will use a timeout if a state is deleted in a constructor' , async ( ) => {
101
+ let el ;
102
+ expect ( ( ) => {
103
+ el = document . createElement ( deleteStateTagName ) ;
104
+ } ) . not . to . throw ( ) ;
105
+
106
+ if ( window . CustomStateSet . isPolyfilled ) {
107
+ await aTimeout ( 100 ) ;
108
+ expect ( el . matches ( '[state--foo]' ) ) . to . be . false ;
109
+ } else {
110
+ expect ( el . matches ( `:--foo` ) ) . to . be . false ;
111
+ }
112
+ } ) ;
87
113
} ) ;
0 commit comments