Skip to content

Commit 7cb6e48

Browse files
committed
explicit scope tests
1 parent bc65e30 commit 7cb6e48

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

packages/@ember/-internals/glimmer/tests/integration/components/runtime-template-compiler-explicit-test.ts

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,136 @@ moduleFor(
336336
}
337337
}
338338
);
339+
340+
moduleFor(
341+
'Strict Mode - Runtime Template Compiler (explicit) - private fields',
342+
class extends RenderingTestCase {
343+
async '@test Can render a private field value'() {
344+
await this.renderComponentModule(() => {
345+
return class extends GlimmerishComponent {
346+
// eslint-disable-next-line no-unused-private-class-members
347+
#greeting = 'Hello, world!';
348+
349+
static {
350+
template('<p>{{this.#greeting}}</p>', {
351+
component: this,
352+
scope: (instance: any) => ({
353+
'#greeting': instance.#greeting,
354+
}),
355+
});
356+
}
357+
};
358+
});
359+
360+
this.assertHTML('<p>Hello, world!</p>');
361+
this.assertStableRerender();
362+
}
363+
364+
async '@test Can render multiple private fields'() {
365+
await this.renderComponentModule(() => {
366+
return class extends GlimmerishComponent {
367+
// eslint-disable-next-line no-unused-private-class-members
368+
#firstName = 'Jane';
369+
// eslint-disable-next-line no-unused-private-class-members
370+
#lastName = 'Doe';
371+
372+
static {
373+
template('<p>{{this.#firstName}} {{this.#lastName}}</p>', {
374+
component: this,
375+
scope: (instance: any) => ({
376+
'#firstName': instance.#firstName,
377+
'#lastName': instance.#lastName,
378+
}),
379+
});
380+
}
381+
};
382+
});
383+
384+
this.assertHTML('<p>Jane Doe</p>');
385+
this.assertStableRerender();
386+
}
387+
388+
async '@test Can use private field method with on modifier'() {
389+
await this.renderComponentModule(() => {
390+
return class extends GlimmerishComponent {
391+
// eslint-disable-next-line no-unused-private-class-members
392+
#message = 'Hello';
393+
394+
// eslint-disable-next-line no-unused-private-class-members
395+
#updateMessage = () => {
396+
this.#message = 'Updated!';
397+
};
398+
399+
static {
400+
template('<button type="button" {{on "click" this.#updateMessage}}>Click</button>', {
401+
component: this,
402+
scope: (instance: any) => ({
403+
on,
404+
'#updateMessage': instance.#updateMessage,
405+
}),
406+
});
407+
}
408+
};
409+
});
410+
411+
this.assertHTML('<button type="button">Click</button>');
412+
this.assertStableRerender();
413+
}
414+
415+
async '@test Can mix private fields with local scope variables'() {
416+
await this.renderComponentModule(() => {
417+
let Greeting = template('<span>{{yield}}</span>');
418+
419+
return class extends GlimmerishComponent {
420+
// eslint-disable-next-line no-unused-private-class-members
421+
#name = 'Ember';
422+
423+
static {
424+
template('<Greeting>Hello, {{this.#name}}!</Greeting>', {
425+
component: this,
426+
scope: (instance: any) => ({
427+
Greeting,
428+
'#name': instance.#name,
429+
}),
430+
});
431+
}
432+
};
433+
});
434+
435+
this.assertHTML('<span>Hello, Ember!</span>');
436+
this.assertStableRerender();
437+
}
438+
439+
async '@test Can use private field with on modifier and fn helper'(assert: QUnit['assert']) {
440+
assert.expect(1);
441+
442+
await this.renderComponentModule(() => {
443+
let checkValue = (value: number) => {
444+
assert.equal(value, 42);
445+
};
446+
447+
return class extends GlimmerishComponent {
448+
// eslint-disable-next-line no-unused-private-class-members
449+
#secretValue = 42;
450+
451+
static {
452+
template(
453+
'<button {{on "click" (fn checkValue this.#secretValue)}}>Click</button>',
454+
{
455+
component: this,
456+
scope: (instance: any) => ({
457+
on,
458+
fn,
459+
checkValue,
460+
'#secretValue': instance.#secretValue,
461+
}),
462+
}
463+
);
464+
}
465+
};
466+
});
467+
468+
this.click('button');
469+
}
470+
}
471+
);

0 commit comments

Comments
 (0)