@@ -117,7 +117,7 @@ describe("Basepattern class tests", function () {
117
117
expect ( pat3 instanceof Pat2 ) . toBeTruthy ( ) ;
118
118
} ) ;
119
119
120
- it ( "4 - The pattern instance is stored on the element itself." , async function ( ) {
120
+ it ( "4.1 - The pattern instance is stored on the element itself." , async function ( ) {
121
121
class Pat extends BasePattern {
122
122
static name = "example" ;
123
123
}
@@ -129,6 +129,44 @@ describe("Basepattern class tests", function () {
129
129
expect ( el [ "pattern-example" ] ) . toBe ( pat ) ;
130
130
} ) ;
131
131
132
+ it ( "4.2 - The same pattern cannot be instantiated on the same element twice." , async function ( ) {
133
+ class Pat extends BasePattern {
134
+ static name = "example" ;
135
+ }
136
+
137
+ const el = document . createElement ( "div" ) ;
138
+ const pat = new Pat ( el ) ;
139
+ await utils . timeout ( 1 ) ;
140
+
141
+ expect ( el [ "pattern-example" ] ) . toBe ( pat ) ;
142
+
143
+ const pat2 = new Pat ( el ) ;
144
+ await utils . timeout ( 1 ) ;
145
+
146
+ expect ( el [ "pattern-example" ] ) . toBe ( pat ) ;
147
+ expect ( el [ "pattern-example" ] ) . not . toBe ( pat2 ) ;
148
+ } ) ;
149
+
150
+ it ( "4.3 - The same pattern can be instantiated on the same element again, after the first was destroyed." , async function ( ) {
151
+ class Pat extends BasePattern {
152
+ static name = "example" ;
153
+ }
154
+
155
+ const el = document . createElement ( "div" ) ;
156
+ const pat = new Pat ( el ) ;
157
+ await utils . timeout ( 1 ) ;
158
+
159
+ expect ( el [ "pattern-example" ] ) . toBe ( pat ) ;
160
+
161
+ pat . destroy ( ) ;
162
+
163
+ const pat2 = new Pat ( el ) ;
164
+ await utils . timeout ( 1 ) ;
165
+
166
+ expect ( el [ "pattern-example" ] ) . not . toBe ( pat ) ;
167
+ expect ( el [ "pattern-example" ] ) . toBe ( pat2 ) ;
168
+ } ) ;
169
+
132
170
it ( "5 - Registers with the registry." , async function ( ) {
133
171
class Pat extends BasePattern {
134
172
static name = "example" ;
0 commit comments