@@ -6,19 +6,19 @@ describe('Attr', () => {
66 @controller
77 // eslint-disable-next-line @typescript-eslint/no-unused-vars
88 class InitializeAttrTest extends HTMLElement {
9- @attr foo = 'hello'
10- bar = 1
9+ @attr fooBar = 'hello'
10+ fooBaz = 1
1111
1212 getCount = 0
1313 setCount = 0
14- #baz = 'world'
15- get baz ( ) {
14+ #bing = 'world'
15+ get bingBaz ( ) {
1616 this . getCount += 1
17- return this . #baz
17+ return this . #bing
1818 }
19- @attr set baz ( value : string ) {
19+ @attr set bingBaz ( value : string ) {
2020 this . setCount += 1
21- this . #baz = value
21+ this . #bing = value
2222 }
2323 }
2424
@@ -32,72 +32,74 @@ describe('Attr', () => {
3232 } )
3333
3434 it ( 'does not alter field values from their initial value' , ( ) => {
35- expect ( instance ) . to . have . property ( 'foo ' , 'hello' )
36- expect ( instance ) . to . have . property ( 'bar ' , 1 )
37- expect ( instance ) . to . have . property ( 'baz ' , 'world' )
35+ expect ( instance ) . to . have . property ( 'fooBar ' , 'hello' )
36+ expect ( instance ) . to . have . property ( 'fooBaz ' , 1 )
37+ expect ( instance ) . to . have . property ( 'bingBaz ' , 'world' )
3838 } )
3939
4040 it ( 'reflects the initial value as an attribute, if not present' , ( ) => {
41- expect ( instance ) . to . have . attribute ( 'data-foo' , 'hello' )
42- expect ( instance ) . to . not . have . attribute ( 'data-bar ' )
43- expect ( instance ) . to . have . attribute ( 'data-baz' , 'world' )
41+ expect ( instance ) . to . have . attribute ( 'data-foo-bar ' , 'hello' )
42+ expect ( instance ) . to . not . have . attribute ( 'data-foo-baz ' )
43+ expect ( instance ) . to . have . attribute ( 'data-bing- baz' , 'world' )
4444 } )
4545
4646 it ( 'prioritises the value in the attribute over the property' , async ( ) => {
47- instance = await fixture ( html `< initialize-attr-test data-foo ="goodbye " data-baz ="universe " /> ` )
48- expect ( instance ) . to . have . property ( 'foo ' , 'goodbye' )
49- expect ( instance ) . to . have . attribute ( 'data-foo' , 'goodbye' )
50- expect ( instance ) . to . have . property ( 'baz ' , 'universe' )
51- expect ( instance ) . to . have . attribute ( 'data-baz' , 'universe' )
47+ instance = await fixture ( html `< initialize-attr-test data-foo-bar ="goodbye " data-bing -baz ="universe " /> ` )
48+ expect ( instance ) . to . have . property ( 'fooBar ' , 'goodbye' )
49+ expect ( instance ) . to . have . attribute ( 'data-foo-bar ' , 'goodbye' )
50+ expect ( instance ) . to . have . property ( 'bingBaz ' , 'universe' )
51+ expect ( instance ) . to . have . attribute ( 'data-bing- baz' , 'universe' )
5252 } )
5353
5454 it ( 'changes the property when the attribute changes' , async ( ) => {
55- instance . setAttribute ( 'data-foo' , 'goodbye' )
55+ instance . setAttribute ( 'data-foo-bar ' , 'goodbye' )
5656 await Promise . resolve ( )
57- expect ( instance ) . to . have . property ( 'foo ' , 'goodbye' )
58- instance . setAttribute ( 'data-baz' , 'universe' )
57+ expect ( instance ) . to . have . property ( 'fooBar ' , 'goodbye' )
58+ instance . setAttribute ( 'data-bing- baz' , 'universe' )
5959 await Promise . resolve ( )
60- expect ( instance ) . to . have . property ( 'baz ' , 'universe' )
60+ expect ( instance ) . to . have . property ( 'bingBaz ' , 'universe' )
6161 } )
6262
6363 it ( 'changes the attribute when the property changes' , ( ) => {
64- instance . foo = 'goodbye'
65- expect ( instance ) . to . have . attribute ( 'data-foo' , 'goodbye' )
66- instance . baz = 'universe'
67- expect ( instance ) . to . have . attribute ( 'data-baz' , 'universe' )
64+ instance . fooBar = 'goodbye'
65+ expect ( instance ) . to . have . attribute ( 'data-foo-bar ' , 'goodbye' )
66+ instance . bingBaz = 'universe'
67+ expect ( instance ) . to . have . attribute ( 'data-bing- baz' , 'universe' )
6868 } )
6969
7070 describe ( 'types' , ( ) => {
7171 it ( 'infers boolean types from property and uses has/toggleAttribute' , async ( ) => {
7272 @controller
7373 // eslint-disable-next-line @typescript-eslint/no-unused-vars
7474 class BooleanAttrTest extends HTMLElement {
75- @attr foo = false
75+ @attr fooBar = false
7676 }
7777
7878 instance = await fixture ( html `< boolean-attr-test /> ` )
7979
80- expect ( instance ) . to . have . property ( 'foo ' , false )
81- expect ( instance ) . to . not . have . attribute ( 'data-foo' )
82- instance . setAttribute ( 'data-foo' , '7' )
80+ expect ( instance ) . to . have . property ( 'fooBar ' , false )
81+ expect ( instance ) . to . not . have . attribute ( 'data-foo-bar ' )
82+ instance . setAttribute ( 'data-foo-bar ' , '7' )
8383 await Promise . resolve ( )
84- expect ( instance ) . to . have . property ( 'foo ' , true )
85- instance . setAttribute ( 'data-foo' , 'hello' )
84+ expect ( instance ) . to . have . property ( 'fooBar ' , true )
85+ instance . setAttribute ( 'data-foo-bar ' , 'hello' )
8686 await Promise . resolve ( )
87- expect ( instance ) . to . have . property ( 'foo ' , true )
88- instance . setAttribute ( 'data-foo' , 'false' )
87+ expect ( instance ) . to . have . property ( 'fooBar ' , true )
88+ instance . setAttribute ( 'data-foo-bar ' , 'false' )
8989 await Promise . resolve ( )
90- expect ( instance ) . to . have . property ( 'foo ' , true )
91- instance . removeAttribute ( 'data-foo' )
90+ expect ( instance ) . to . have . property ( 'fooBar ' , true )
91+ instance . removeAttribute ( 'data-foo-bar ' )
9292 await Promise . resolve ( )
93- expect ( instance ) . to . have . property ( 'foo' , false )
94- instance . foo = true
95- expect ( instance ) . to . have . attribute ( 'data-foo' , '' )
96- instance . foo = false
97- expect ( instance ) . to . not . have . attribute ( 'data-foo' )
98- instance . removeAttribute ( 'data-foo' )
93+ expect ( instance ) . to . have . property ( 'fooBar' , false )
94+ instance . fooBar = true
9995 await Promise . resolve ( )
100- expect ( instance ) . to . have . property ( 'foo' , false )
96+ expect ( instance ) . to . have . attribute ( 'data-foo-bar' , '' )
97+ instance . fooBar = false
98+ await Promise . resolve ( )
99+ expect ( instance ) . to . not . have . attribute ( 'data-foo-bar' )
100+ instance . removeAttribute ( 'data-foo-bar' )
101+ await Promise . resolve ( )
102+ expect ( instance ) . to . have . property ( 'fooBar' , false )
101103 } )
102104
103105 it ( 'avoids infinite loops' , async ( ) => {
@@ -106,20 +108,20 @@ describe('Attr', () => {
106108 class LoopAttrTest extends HTMLElement {
107109 count = 0
108110 @attr
109- get foo ( ) {
111+ get fooBar ( ) {
110112 return ++ this . count
111113 }
112- set foo ( value ) {
114+ set fooBar ( value ) {
113115 this . count += 1
114116 }
115117 }
116118 instance = await fixture ( html `< loop-attr-test /> ` )
117119
118- expect ( instance ) . to . have . property ( 'foo ' )
119- instance . foo = 1
120- instance . setAttribute ( 'data-foo' , '2' )
121- instance . foo = 3
122- instance . setAttribute ( 'data-foo' , '4' )
120+ expect ( instance ) . to . have . property ( 'fooBar ' )
121+ instance . fooBar = 1
122+ instance . setAttribute ( 'data-foo-bar ' , '2' )
123+ instance . fooBar = 3
124+ instance . setAttribute ( 'data-foo-bar ' , '4' )
123125 } )
124126 } )
125127
0 commit comments