-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d436dc4
commit e8f4a13
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
packages/@glimmer-workspace/integration-tests/test/lazy-initialization-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { assign } from '@glimmer/util'; | ||
import { | ||
BaseEnv, | ||
GlimmerishComponent, | ||
JitRenderDelegate, | ||
RenderTest, | ||
suite, | ||
test, | ||
tracked, | ||
} from '..'; | ||
|
||
class LazyInitializationTest extends RenderTest { | ||
static suiteName = 'Application test: lazy initialization'; | ||
|
||
@test 'Should be able to lazily initialize a tracked property'() { | ||
class X extends GlimmerishComponent { | ||
@tracked _counts: number | undefined = undefined; | ||
|
||
get counts() { | ||
if (this._counts === undefined) { | ||
this._counts = 0; | ||
} | ||
|
||
return this._counts; | ||
} | ||
|
||
increment = () => this._counts!++; | ||
} | ||
this.registerComponent( | ||
'Glimmer', | ||
'HelloWorld', | ||
` | ||
{{this._counts}} | ||
{{this.counts}} | ||
`, | ||
X | ||
); | ||
|
||
this.render(`<HelloWorld />`); | ||
|
||
this.assertHTML(`0 0`); | ||
} | ||
} | ||
|
||
suite(LazyInitializationTest, JitRenderDelegate, { | ||
env: assign({}, BaseEnv, { | ||
enableDebugTooling: false, | ||
}), | ||
}); |