You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+34-25Lines changed: 34 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,34 +116,42 @@ Import the vhs test function. Works almost identically to `tape`, except your t
116
116
117
117
### `vhs(description, async testFn)`
118
118
119
-
Describe your test with a `description` string, and pass an async `testFn` which receives the `t` assertion variable. This assertion variable includes all of the `tape` helpers, with a few extras that are helpful for testig dom elements and components.
119
+
Describe your test with a `description` string, and pass an async `testFn` which receives the `t` assertion variable. This assertion variable includes all of the `tape` helpers, with a few extras that are helpful for testing dom elements and components.
120
120
121
121
### `vhs.delay(ms)(description, async testFn)`
122
122
123
+
Delay all vhs-test helpers by `ms`, unless otherwise noted in the test helper description.
124
+
123
125
### `vhs.slow(description, async testFn)`
124
126
127
+
Shorthand for `vhs.delay(500)`.
128
+
125
129
### `vhs.skip(description, async testFn)`
126
130
131
+
Same as `tape``t.skip`.
132
+
127
133
### `vhs.only(description, async testFn)`
128
134
135
+
Same as `tape``t.only`.
136
+
129
137
### `t.element`
130
138
131
139
The HTMLElement element where your test should work inside.
132
140
133
-
### `await t.appendChild(el)`
141
+
### `await t.appendChild(el, [msg])`
134
142
135
-
Takes an element, append it and then waits for onload.
143
+
Takes an element, append it and then waits for onload. Asserts when complete with a `msg`.
136
144
```js
137
145
constnewDiv=document.createElement('div')
138
146
newDiv.innerText='New div to append'
139
-
awaitt.appendChild(newDiv)
147
+
awaitt.appendChild(newDiv, 'Appended newDiv')
140
148
```
141
149
142
-
### `await t.sleep(ms)`
150
+
### `await t.sleep(ms, [msg])`
143
151
144
-
Async sleepf for `ms`.
152
+
Async sleep for `ms` and asserts when complete with `msg`.
145
153
146
-
### `await t.onload(element)`
154
+
### `await t.onload(element, [msg])`
147
155
148
156
Wait for the element to be fully mounted and rendered into the page.
Same as `t.onload` except it lets you wait for an element to be fully unloaded from the document.
159
167
160
-
### `await t.raf()`
168
+
### `await t.raf([msg])`
161
169
162
-
Lets you wait for an animation frame to fire. This gives an opportunity for the page to repaint and reflow after making modifications to the DOM. Always waits for a RequestAnimationFrame and ignores any delay paramters.
170
+
Lets you wait for an animation frame to fire. This gives an opportunity for the page to repaint and reflow after making modifications to the DOM. Always waits for a RequestAnimationFrame and ignores any delay parameters. Only asserts when passed a `msg`. Does not insert additional delays.
163
171
164
-
### `await t.delay()`
172
+
### `await t.delay([msg])`
165
173
166
-
Similar to `await t.raf()`, except this will sleep when a test delay is set, so you can watch your test in slow motion. When no delay is set, these will revert to just a `t.raf()`.
174
+
Similar to `await t.raf()`, except this will sleep when a test delay is set, so you can watch your test in slow motion. When no delay is set, these will revert to just a `t.raf()`. Only asserts when passed a `msg`.
Accepts a query selector string that resolves to an element or an element. Calls `element.focus()` followed by a `t.delay()`.
175
183
176
-
### `await t.type(string, [event])`
184
+
### `await t.type(string, [event], [msg])`
177
185
178
186
Dispatches `new window.KeyboardEvent` defaulting to the `keydown` event, for each character in `string`. Helpful for typing into the currently focused element on screen. This helper is a WIP, and doesn't work everywhere. Includes a `t.delay()` call so updates are rendered every keypress.
179
187
188
+
### `await once(emitter, name, [msg])`
189
+
190
+
Shortcut to use [`'events.once'`](https://github.com/davidmarkclements/events.once#readme), which is useful for catching events as promises.
191
+
180
192
## FAQ
181
193
194
+
### How do I run vhs-tests?
195
+
196
+
`vhs-tests` are geared towards a Node.js style common.js environment, so you will need a bundler like browserify or webpack to bundle them into the browser or an electron app.
197
+
182
198
### How do I load global styles or assumed side effects?
183
199
184
-
If your components or tests require global styles or sprite sheets to work, write a module that mounts these assets into the page as a side effect of `require`ing or `import`ing that file.
200
+
If your components or tests require global styles or sprite sheets to work, write a module that mounts these assets into the page as a side effect of `require`ing or `import`ing that file.
185
201
186
-
In each test, require the global style module, and your module loadig system will de-duplicate the calls to the global side-effects, and each of your tests will still work.
202
+
In each test, require the global style module, and your module loading system will de-duplicate the calls to the global side-effects, and each of your tests will still work.
Additionally, you can always load a test bundle into a page with styles and spritesheets already mounted, or utilize features in your bundler to hande that insertion for you.
206
-
207
-
## See also
221
+
Additionally, you can always load a test bundle into a page with styles and spritesheets already mounted, or utilize features in your bundler to hande that insertion for you.
0 commit comments