Skip to content

Commit

Permalink
[lit-html] Add test for sync AsyncDirective.setValue() call (#2128)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfagnani committed Sep 2, 2021
1 parent 61fc945 commit cc5c3a0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-squids-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'lit-html': patch
---

Add test for AsyncDirectives that synchronously call this.setValue()
19 changes: 19 additions & 0 deletions packages/lit-html/src/test/lit-html_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2176,6 +2176,7 @@ suite('lit-html', () => {
}
const aDirective = directive(ADirective);
let aDirectiveInst: ADirective;

const bDirective = directive(
class extends Directive {
count = 0;
Expand All @@ -2185,6 +2186,24 @@ suite('lit-html', () => {
}
);

const syncAsyncDirective = directive(
class extends AsyncDirective {
render(x: string) {
this.setValue(x);
return noChange;
}
}
);

test('async directive can call setValue synchronously', () => {
assertRender(
html`<div foo=${syncAsyncDirective('test')}>${syncAsyncDirective(
'test'
)}</div>`,
'<div foo="test">test</div>'
);
});

test('async directives in ChildPart', async () => {
const template = (promise: Promise<unknown>) =>
html`<div>${aDirective(promise)}</div>`;
Expand Down

0 comments on commit cc5c3a0

Please sign in to comment.