Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(lit): add reflected property tests #2116

Merged
merged 1 commit into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/weak-planets-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

add lit renderer reflection tests
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
6 changes: 6 additions & 0 deletions packages/astro/test/lit-element.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down