@@ -17,19 +17,7 @@ export default interface User {
1717
1818Then our component might be defined like this:
1919
20- ``` handlebars {data-filename="app/components/profile.hbs"}
21- <div class='user-profile' ...attributes>
22- <img
23- src={{this.avatarUrl}}
24- alt={{this.description}}
25- class='avatar'
26- data-test-avatar
27- />
28- <span class='name' data-test-name>{{@user.displayName}}</span>
29- </div>
30- ```
31-
32- ``` typescript {data-filename="app/components/profile.ts"}
20+ ``` gts {data-filename="app/components/profile.gts"}
3321import Component from '@glimmer/component';
3422import type User from 'app/types/user';
3523import { randomAvatarURL } from 'app/utils/avatar';
@@ -50,15 +38,26 @@ export default class Profile extends Component<ProfileSignature> {
5038 ? `${this.args.user.displayName}'s custom profile picture`
5139 : 'a randomly generated placeholder avatar';
5240 }
41+
42+ <template>
43+ <div class='user-profile' ...attributes>
44+ <img
45+ src={{this.avatarUrl}}
46+ alt={{this.description}}
47+ class='avatar'
48+ data-test-avatar
49+ />
50+ <span class='name' data-test-name>{{@user.displayName}}</span>
51+ </div>
52+ </template>
5353}
5454```
5555
5656To test the ` Profile ` component, we need to set up a ` User ` on ` this ` to pass into the component as an argument. With TypeScript on our side, we can even make sure our user actually has the correct type!
5757
58- ``` typescript {data-filename="tests/integration/components/profile.ts "}
58+ ``` gts {data-filename="tests/integration/components/profile.gts "}
5959import { module, test } from 'qunit';
6060import { render } from '@ember/test-helpers';
61- import { hbs } from ' ember-cli-htmlbars' ;
6261
6362import { setupRenderingTest } from 'app/tests/helpers';
6463import type User from 'app/types/user';
@@ -73,7 +72,7 @@ module('Integration | Component | Profile', function (hooks) {
7372 };
7473 this.user = user;
7574
76- await render (hbs ` < Profile @user={{this.user}}` );
75+ await render(<template>< Profile @user={{this.user}} /></template> );
7776
7877 assert.dom('[data-test-name]').hasText(this.user.displayName);
7978 assert
@@ -88,7 +87,7 @@ module('Integration | Component | Profile', function (hooks) {
8887 };
8988 this.user = user;
9089
91- await render (hbs ` < Profile @user={{this.user}}` );
90+ await render(<template>< Profile @user={{this.user}} /></template> );
9291
9392 assert.dom('[data-test-name]').hasText(this.user.displayName);
9493 assert
@@ -120,11 +119,10 @@ test('...', function (this: Context, assert) {});
120119
121120Putting it all together, this is what our updated test definition would look like:
122121
123- ``` typescript {data-filename="tests/integration/components/profile.ts "}
122+ ``` gts {data-filename="tests/integration/components/profile.gts "}
124123import { module, test } from 'qunit';
125124import { render } from '@ember/test-helpers';
126125import type { TestContext } from '@ember/test-helpers';
127- import { hbs } from ' ember-cli-htmlbars' ;
128126
129127import { setupRenderingTest } from 'app/tests/helpers';
130128import type User from 'app/types/user';
@@ -142,7 +140,7 @@ module('Integration | Component | Profile', function (hooks) {
142140 avatarUrl: 'https://example.com/star-wars/rey',
143141 };
144142
145- await render (hbs ` < Profile @user={{this.user}}` );
143+ await render(<template>< Profile @user={{this.user}} /></template> );
146144
147145 assert.dom('[data-test-name]').hasText(this.user.displayName);
148146 assert
@@ -156,7 +154,7 @@ module('Integration | Component | Profile', function (hooks) {
156154 displayName: 'Rey',
157155 };
158156
159- await render (hbs ` < Profile @user={{this.user}}` );
157+ await render(<template>< Profile @user={{this.user}} /></template> );
160158
161159 assert.dom('[data-test-name]').hasText(this.user.displayName);
162160 assert
0 commit comments