test(lit): add reflected property tests (#2116)

This commit is contained in:
Elliott Marquez 2021-12-06 11:23:09 -08:00 committed by GitHub
parent c0f29bcf8c
commit d9d3906a3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
add lit renderer reflection tests

View file

@ -7,6 +7,9 @@ export class MyElement extends LitElement {
bool: {type: Boolean},
str: {type: String, attribute: 'str-attr'},
obj: {type: Object},
reflectedBool: {type: Boolean, reflect: true},
reflectedStr: {type: String, reflect: true, attribute: 'reflected-str'},
reflectedStrProp: {type: String, reflect: true, attribute: 'reflected-str-prop'},
}
constructor() {
@ -16,6 +19,9 @@ export class MyElement extends LitElement {
this.obj = {data: null};
// not a reactive property
this.foo = 'not initialized';
// reflected props
this.reflectedBool = true;
this.reflectedStr = 'default reflected string';
}
render() {
return html`

View file

@ -11,7 +11,8 @@ import '../components/my-element.js';
foo="bar"
str-attr={'initialized'}
bool={false}
obj={{data: 1}}>
obj={{data: 1}}
reflectedStrProp={'initialized reflected'}>
</my-element>
</body>
</html>
</html>

View file

@ -50,6 +50,12 @@ describe('LitElement test', () => {
expect($('my-element').attr('obj')).to.equal(undefined);
expect($('my-element').attr('bool')).to.equal(undefined);
expect($('my-element').attr('str')).to.equal(undefined);
// test 7: reflected reactive props are rendered as attributes
expect($('my-element').attr('reflectedbool')).to.equal('');
expect($('my-element').attr('reflected-str')).to.equal('default reflected string');
expect($('my-element').attr('reflected-str-prop')).to.equal('initialized reflected');
});
// Skipped because not supported by Lit