|
| 1 | +import { tracked } from '@ember/-internals/metal'; |
1 | 2 | import { template } from '@ember/template-compiler/runtime';
|
2 |
| -import { RenderingTestCase, defineSimpleModifier, moduleFor } from 'internal-test-helpers'; |
| 3 | +import { RenderingTestCase, defineSimpleModifier, moduleFor, runTask } from 'internal-test-helpers'; |
3 | 4 | import GlimmerishComponent from '../../utils/glimmerish-component';
|
4 | 5 | import { on } from '@ember/modifier/on';
|
5 | 6 | import { fn } from '@ember/helper';
|
6 | 7 |
|
7 | 8 | moduleFor(
|
8 | 9 | 'Strict Mode - Runtime Template Compiler (implicit)',
|
9 | 10 | class extends RenderingTestCase {
|
| 11 | + async '@test can have in-scope tracked data'(assert: Assert) { |
| 12 | + class State { |
| 13 | + @tracked str = `hello there`; |
| 14 | + |
| 15 | + get component() { |
| 16 | + assert.step('get component'); |
| 17 | + |
| 18 | + let getStr = () => { |
| 19 | + assert.step('getStr()'); |
| 20 | + return this.str; |
| 21 | + }; |
| 22 | + |
| 23 | + hide(getStr); |
| 24 | + |
| 25 | + return template(`{{ (getStr) }}`, { |
| 26 | + eval() { |
| 27 | + return eval(arguments[0]); |
| 28 | + }, |
| 29 | + }); |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + let state = new State(); |
| 34 | + |
| 35 | + await this.renderComponentModule(() => { |
| 36 | + return template('<state.component />', { |
| 37 | + eval() { |
| 38 | + assert.step('eval'); |
| 39 | + return eval(arguments[0]); |
| 40 | + }, |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + this.assertHTML('hello there'); |
| 45 | + this.assertStableRerender(); |
| 46 | + assert.verifySteps([ |
| 47 | + // for every value in the component, for eevry node traversed in the compiler |
| 48 | + 'eval', // precompileJSON -> ... ElementNode -> ... -> lexicalScope -> isScope('state', ...) |
| 49 | + 'eval', // "..." |
| 50 | + 'eval', // "..." |
| 51 | + 'eval', // creating the templateFactory |
| 52 | + 'get component', |
| 53 | + 'getStr()', |
| 54 | + ]); |
| 55 | + |
| 56 | + runTask(() => (state.str += '!')); |
| 57 | + |
| 58 | + this.assertHTML('hello there!'); |
| 59 | + this.assertStableRerender(); |
| 60 | + assert.verifySteps(['getStr()']); |
| 61 | + } |
| 62 | + |
10 | 63 | async '@test Can use a component in scope'() {
|
11 | 64 | await this.renderComponentModule(() => {
|
12 | 65 | let Foo = template('Hello, world!', {
|
|
0 commit comments