@@ -56,7 +56,7 @@ automatically removed from `production` builds:
56
56
<article>
57
57
<h1 data-test-post-title data-test-resource-id={{post.id}}>{{post.title}}</h1>
58
58
<p>{{post.body}}</p>
59
- <LikeButton data-test-like-button / >
59
+ <button data-test-like-button>Like</button >
60
60
</article>
61
61
```
62
62
@@ -69,108 +69,29 @@ assert.dom('[data-test-post-title]').hasText('Ember is great!');
69
69
await click (' [data-test-like-button]' );
70
70
```
71
71
72
- ### Usage in Components
72
+ ### Usage with Components
73
73
74
- You can also use ` data-test-* ` attributes on components in curly component
75
- invocation:
76
-
77
- ``` handlebars
78
- {{comments-list data-test-comments-for=post.id}}
79
- ```
80
-
81
- These ` data-test-* ` attributes will be bound automatically and available
82
- as data attributes on the ` <div> ` wrapping the component template:
83
-
84
- ``` html
85
- <div id =" ember123" data-test-comments-for =" 42" >
86
- <!-- comments -->
87
- </div >
88
- ```
89
-
90
- ### Usage with tagless components
91
-
92
- Since tagless components do not have a root element, ` data-test-* ` attributes
93
- passed to them cannot be bound to the DOM. If you try to pass a ` data-test-* `
94
- attribute to a tagless component, or define one in its Javascript class,
95
- ` ember-test-selectors ` will throw an assertion error.
96
-
97
- However, there are some cases where you might want to pass a ` data-test-* `
98
- attribute to a tagless component, for example a tagless wrapper component:
99
-
100
- ``` js
101
- // comment-wrapper.js
102
- export default class ComponentWrapper extends Component {
103
- tagName = ' ' ;
104
- }
105
- ```
74
+ You can use the same syntax also for component invocations:
106
75
107
76
``` hbs
108
- {{!-- comment-wrapper.hbs --}}
109
- Comment:
110
- <CommentListItem @comment={{comment}} data-test-comment-id={{data-test-comment-id}} />
77
+ <Spinner @color="blue" data-test-spinner>
111
78
```
112
79
113
- ``` handlebars
114
- {{!-- comment-list.hbs --}}
115
- {{#each comments as |comment|}}
116
- <CommentWrapper @comment={{comment}} @data-test-comment-id={{comment.id}} />
117
- {{/each}}
118
- ```
80
+ Inside the ` Spinner ` component template the ` data-test-spinner ` attribute will
81
+ be applied to the element that has ` ...attributes ` on it, or on the component
82
+ wrapper ` div ` element if you don't use ` tagName = '' ` .
119
83
120
- In this case, to prevent the assertion on the specific ` comment-wrapper `
121
- component, you can specify ` supportsDataTestProperties ` on the class:
84
+ If you still use the old curly invocation syntax for components you can pass
85
+ ` data-test-* ` arguments to the components and they will automatically be bound
86
+ on the wrapper element too:
122
87
123
- ``` js
124
- // comment-wrapper.js
125
- export default class ComponentWrapper extends Component {
126
- tagName = ' ' ;
127
- supportsDataTestProperties = true ;
128
- }
129
- ```
130
-
131
- ` supportsDataTestProperties ` , like ` data-test-* ` properties, will be stripped
132
- from the build.
133
-
134
- #### With splattributes
135
- Splattributes of angle brackets invocations, introduced in Ember.js 3.4 or
136
- available through the
137
- [ ember-angle-bracket-invocation-polyfill] ( https://github.com/rwjblue/ember-angle-bracket-invocation-polyfill )
138
- for earlier versions of Ember.js, work well with test selectors and tagless
139
- components.
140
-
141
- For instance, we have a ` SpecialButton ` that wraps a ` <button> ` element. We can
142
- then pass arbitrary test selectors through splattributes, as follows:
143
-
144
- ``` js
145
- // special-button.js
146
- export default class SpecialButton extends Component {
147
- tagName = ' ' ;
148
- }
149
- ```
150
-
151
- ``` hbs
152
- {{!-- special-button.hbs --}}
153
- <button ...attributes>
154
- {{yield}}
155
- </button>
156
- ```
157
-
158
- Then
159
-
160
- ``` hbs
161
- <SpecialButton data-test-description="invite-user">
162
- Invite
163
- </SpecialButton>
88
+ ``` handlebars
89
+ {{spinner color="blue" data-test-spinner=true}}
164
90
```
165
91
166
- will yield
167
-
92
+ Please note that this only works for components based on ` @ember/component ` ,
93
+ but not ` @glimmer/component ` .
168
94
169
- ``` html
170
- <button data-test-description =" invite-user" >
171
- Invite
172
- </button >
173
- ```
174
95
175
96
### Usage in Ember addons
176
97
0 commit comments