Skip to content

Commit 365868b

Browse files
committed
Merge branch 'master' into preview-types
2 parents 841984e + 87dfbf4 commit 365868b

19 files changed

Lines changed: 678 additions & 364 deletions

API.md

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ Emulating filling an input with text using `fillIn`
223223
fillIn('input', 'hello world');
224224
```
225225

226-
Returns **[Promise][66]<([Element][65] | void)>** resolves when the application is settled
226+
Returns **[Promise][66]\<void>** resolves when the application is settled
227227

228228
### focus
229229

@@ -311,7 +311,7 @@ keyboard.
311311

312312
#### Parameters
313313

314-
* `options` **[Object][72]?** optional tab behaviors
314+
* `options` **[Object][72]?** optional tab behaviors (optional, default `{}`)
315315

316316
* `options.backwards` **[boolean][71]** indicates if the the user navigates backwards (optional, default `false`)
317317
* `options.unRestrainTabIndex` **[boolean][71]** indicates if tabbing should throw an error when tabindex is greater than 0 (optional, default `false`)
@@ -376,7 +376,7 @@ Emulating tapping a button using `tap`
376376
tap('button');
377377
```
378378

379-
Returns **[Promise][66]<([Event][73] | [Array][70]<[Event][73]> | void)>** resolves when settled
379+
Returns **[Promise][66]\<void>** resolves when settled
380380

381381
### triggerEvent
382382

@@ -394,7 +394,7 @@ Using `triggerEvent` to upload a file
394394

395395
When using `triggerEvent` to upload a file the `eventType` must be `change` and you must pass the
396396
`options` param as an object with a key `files` containing an array of
397-
[Blob][74].
397+
[Blob][73].
398398

399399
```javascript
400400
triggerEvent(
@@ -406,8 +406,8 @@ triggerEvent(
406406

407407
Using `triggerEvent` to upload a dropped file
408408

409-
When using `triggerEvent` to handle a dropped (via drag-and-drop) file, the `eventType` must be `drop`. Assuming your `drop` event handler uses the [DataTransfer API][75],
410-
you must pass the `options` param as an object with a key of `dataTransfer`. The `options.dataTransfer` object should have a `files` key, containing an array of [File][76].
409+
When using `triggerEvent` to handle a dropped (via drag-and-drop) file, the `eventType` must be `drop`. Assuming your `drop` event handler uses the [DataTransfer API][74],
410+
you must pass the `options` param as an object with a key of `dataTransfer`. The `options.dataTransfer` object should have a `files` key, containing an array of [File][75].
411411

412412
```javascript
413413
triggerEvent(
@@ -426,8 +426,8 @@ Returns **[Promise][66]\<void>** resolves when the application is settled
426426
### triggerKeyEvent
427427

428428
Triggers a keyboard event of given type in the target element.
429-
It also requires the developer to provide either a string with the [`key`][77]
430-
or the numeric [`keyCode`][78] of the pressed key.
429+
It also requires the developer to provide either a string with the [`key`][76]
430+
or the numeric [`keyCode`][77] of the pressed key.
431431
Optionally the user can also provide a POJO with extra modifiers for the event.
432432

433433
#### Parameters
@@ -493,6 +493,14 @@ Find the first element matched by the given selector. Equivalent to calling
493493

494494
* `selector` **[string][64]** the selector to search for
495495

496+
#### Examples
497+
498+
Find all of the elements matching '.my-selector'.
499+
500+
```javascript
501+
findAll('.my-selector');
502+
```
503+
496504
Returns **[Element][65]** matched element or null
497505

498506
### findAll
@@ -505,12 +513,29 @@ of a `NodeList`.
505513

506514
* `selector` **[string][64]** the selector to search for
507515

516+
#### Examples
517+
518+
Finding the first element with id 'foo'
519+
520+
```javascript
521+
find('#foo');
522+
```
523+
508524
Returns **[Array][70]** array of matched elements
509525

510526
### getRootElement
511527

512528
Get the root element of the application under test (usually `#ember-testing`)
513529

530+
#### Examples
531+
532+
Getting the root element of the application and checking that it is equal
533+
to the element with id 'ember-testing'.
534+
535+
```javascript
536+
assert.equal(getRootElement(), document.querySelector('#ember-testing'));
537+
```
538+
514539
Returns **[Element][65]** the root element
515540

516541
## Routing Helpers
@@ -596,7 +621,7 @@ while *not* settled (e.g. "loading" or "pending" states).
596621

597622
#### Parameters
598623

599-
* `callback` **[Function][79]** the callback to use for testing when waiting should stop
624+
* `callback` **[Function][78]** the callback to use for testing when waiting should stop
600625
* `options` **[Object][72]?** options used to override defaults (optional, default `{}`)
601626

602627
* `options.timeout` **[number][69]** the maximum amount of time to wait (optional, default `1000`)
@@ -856,9 +881,9 @@ element).
856881

857882
#### Parameters
858883

859-
* `context` **[Object][72]** the context to setup for rendering
884+
* `context` **TestContext** the context to setup for rendering
860885

861-
Returns **[Promise][66]<[Object][72]>** resolves with the context that was setup
886+
Returns **[Promise][66]\<RenderingTestContext>** resolves with the context that was setup
862887

863888
### getApplication
864889

@@ -891,7 +916,7 @@ Sets up the basic framework used by application tests.
891916

892917
* `context` **[Object][72]** the context to setup
893918

894-
Returns **[Promise][66]<[Object][72]>** resolves with the context that was setup
919+
Returns **[Promise][66]\<void>** resolves when the context is set up
895920

896921
### validateErrorHandler
897922

@@ -906,7 +931,7 @@ everything is on fire...
906931

907932
#### Parameters
908933

909-
* `callback` **[Function][79]** the callback to validate (optional, default `Ember.onerror`)
934+
* `callback` **[Function][78]** the callback to validate (optional, default `Ember.onerror`)
910935

911936
#### Examples
912937

@@ -931,7 +956,7 @@ without an `onError` argument.
931956

932957
#### Parameters
933958

934-
* `onError` **[Function][79]** the onError function to be set on Ember.onerror
959+
* `onError` **[Function][78]** the onError function to be set on Ember.onerror
935960

936961
#### Examples
937962

@@ -1018,7 +1043,7 @@ Returns deprecations which have occured so far for a the current test context
10181043

10191044
### Parameters
10201045

1021-
* `callback` **CallableFunction?** The callback that when executed will have its DeprecationFailure recorded
1046+
* `callback` **[Function][78]?** The callback that when executed will have its DeprecationFailure recorded
10221047

10231048
### Examples
10241049

@@ -1076,7 +1101,7 @@ Returns warnings which have occured so far for a the current test context
10761101

10771102
### Parameters
10781103

1079-
* `callback` **CallableFunction?** The callback that when executed will have its warnings recorded
1104+
* `callback` **[Function][78]?** The callback that when executed will have its warnings recorded
10801105

10811106
### Examples
10821107

@@ -1216,23 +1241,23 @@ Returns **([Array][70]\<Warning> | [Promise][66]<[Array][70]\<Warning>>)** An ar
12161241

12171242
[54]: #getdeprecations
12181243

1219-
[55]: #examples-19
1244+
[55]: #examples-22
12201245

12211246
[56]: #getdeprecationsduringcallback
12221247

12231248
[57]: #parameters-29
12241249

1225-
[58]: #examples-20
1250+
[58]: #examples-23
12261251

12271252
[59]: #getwarnings
12281253

1229-
[60]: #examples-21
1254+
[60]: #examples-24
12301255

12311256
[61]: #getwarningsduringcallback
12321257

12331258
[62]: #parameters-30
12341259

1235-
[63]: #examples-22
1260+
[63]: #examples-25
12361261

12371262
[64]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
12381263

@@ -1252,16 +1277,14 @@ Returns **([Array][70]\<Warning> | [Promise][66]<[Array][70]\<Warning>>)** An ar
12521277

12531278
[72]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
12541279

1255-
[73]: https://developer.mozilla.org/docs/Web/API/Event
1256-
1257-
[74]: https://developer.mozilla.org/en-US/docs/Web/API/Blob
1280+
[73]: https://developer.mozilla.org/en-US/docs/Web/API/Blob
12581281

1259-
[75]: https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer
1282+
[74]: https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer
12601283

1261-
[76]: https://developer.mozilla.org/en-US/docs/Web/API/File
1284+
[75]: https://developer.mozilla.org/en-US/docs/Web/API/File
12621285

1263-
[77]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
1286+
[76]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
12641287

1265-
[78]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
1288+
[77]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
12661289

1267-
[79]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
1290+
[78]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function

CHANGELOG.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1+
# CHANGELOG
12

3+
## v2.9.0 (2022-12-14)
24

5+
#### :rocket: Enhancement
6+
* [#1269](https://github.com/emberjs/ember-test-helpers/pull/1269) Re-export hasEmberVersion (and its type) from @ember/test-helpers ([@gitKrystan](https://github.com/gitKrystan))
7+
* [#1278](https://github.com/emberjs/ember-test-helpers/pull/1278) perf: Remove excessive destroy call ([@runspired](https://github.com/runspired))
8+
* [#1234](https://github.com/emberjs/ember-test-helpers/pull/1234) Introduce public TypeScript support ([@chriskrycho](https://github.com/chriskrycho))
39

10+
#### :bug: Bug Fix
11+
* [#1277](https://github.com/emberjs/ember-test-helpers/pull/1277) Actually publish .d.ts ([@gitKrystan](https://github.com/gitKrystan))
12+
* [#1270](https://github.com/emberjs/ember-test-helpers/pull/1270) Fix typesVersions path ([@gitKrystan](https://github.com/gitKrystan))
13+
* [#1233](https://github.com/emberjs/ember-test-helpers/pull/1233) Add more keyCode mappings ([@CvX](https://github.com/CvX))
414

15+
#### :memo: Documentation
16+
* [#1259](https://github.com/emberjs/ember-test-helpers/pull/1259) DOCS: API: publish docs for tab ([@geneukum](https://github.com/geneukum))
517

6-
7-
8-
9-
18+
#### Committers: 5
19+
- Chris Krycho ([@chriskrycho](https://github.com/chriskrycho))
20+
- Chris Thoburn ([@runspired](https://github.com/runspired))
21+
- Geordan Neukum ([@geneukum](https://github.com/geneukum))
22+
- Jarek Radosz ([@CvX](https://github.com/CvX))
23+
- Krystan HuffMenne ([@gitKrystan](https://github.com/gitKrystan))
1024

1125
## v2.8.1 (2022-05-19)
1226

addon-test-support/@ember/test-helpers/dom/-get-element.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import getRootElement from './get-root-element';
22
import Target, { isDocument, isElement } from './-target';
33

4+
function getElement<
5+
K extends keyof (HTMLElementTagNameMap | SVGElementTagNameMap)
6+
>(target: K): (HTMLElementTagNameMap[K] | SVGElementTagNameMap[K]) | null;
7+
function getElement<K extends keyof HTMLElementTagNameMap>(
8+
target: K
9+
): HTMLElementTagNameMap[K] | null;
10+
function getElement<K extends keyof SVGElementTagNameMap>(
11+
target: K
12+
): SVGElementTagNameMap[K] | null;
413
function getElement(target: string): Element | null;
514
function getElement(target: Element): Element;
615
function getElement(target: Document): Document;

addon-test-support/@ember/test-helpers/dom/fill-in.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ registerHook('fillIn', 'start', (target: Target, text: string) => {
2121
@public
2222
@param {string|Element} target the element or selector to enter text into
2323
@param {string} text the text to fill into the target element
24-
@return {Promise<Element | void>} resolves when the application is settled
24+
@return {Promise<void>} resolves when the application is settled
2525
2626
@example
2727
<caption>
@@ -30,10 +30,7 @@ registerHook('fillIn', 'start', (target: Target, text: string) => {
3030
3131
fillIn('input', 'hello world');
3232
*/
33-
export default function fillIn(
34-
target: Target,
35-
text: string
36-
): Promise<Element | void> {
33+
export default function fillIn(target: Target, text: string): Promise<void> {
3734
return Promise.resolve()
3835
.then(() => runHooks('fillIn', 'start', target, text))
3936
.then(() => {

addon-test-support/@ember/test-helpers/dom/find-all.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
import getElements from './-get-elements';
22
import { toArray } from '../ie-11-polyfills';
33

4+
// Derived, with modification, from the types for `querySelectorAll`. These
5+
// would simply be defined as a tweaked re-export as `querySelector` is, but it
6+
// is non-trivial (to say the least!) to preserve overloads like this while also
7+
// changing the return type (from `NodeListOf` to `Array`).
8+
export default function findAll<
9+
K extends keyof (HTMLElementTagNameMap | SVGElementTagNameMap)
10+
>(selector: K): Array<HTMLElementTagNameMap[K] | SVGElementTagNameMap[K]>;
11+
export default function findAll<K extends keyof HTMLElementTagNameMap>(
12+
selector: K
13+
): Array<HTMLElementTagNameMap[K]>;
14+
export default function findAll<K extends keyof SVGElementTagNameMap>(
15+
selector: K
16+
): Array<SVGElementTagNameMap[K]>;
17+
export default function findAll(selector: string): Element[];
418
/**
519
Find all elements matched by the given selector. Similar to calling
620
`querySelectorAll()` on the test root element, but returns an array instead
@@ -9,6 +23,12 @@ import { toArray } from '../ie-11-polyfills';
923
@public
1024
@param {string} selector the selector to search for
1125
@return {Array} array of matched elements
26+
27+
@example
28+
<caption>
29+
Finding the first element with id 'foo'
30+
</caption>
31+
find('#foo');
1232
*/
1333
export default function findAll(selector: string): Element[] {
1434
if (!selector) {

addon-test-support/@ember/test-helpers/dom/find.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
import getElement from './-get-element';
22

3+
// Derived from `querySelector` types.
4+
export default function find<
5+
K extends keyof (HTMLElementTagNameMap | SVGElementTagNameMap)
6+
>(selector: K): HTMLElementTagNameMap[K] | SVGElementTagNameMap[K] | null;
7+
export default function find<K extends keyof HTMLElementTagNameMap>(
8+
selector: K
9+
): HTMLElementTagNameMap[K] | null;
10+
export default function find<K extends keyof SVGElementTagNameMap>(
11+
selector: K
12+
): SVGElementTagNameMap[K] | null;
13+
export default function find(selector: string): Element | null;
314
/**
415
Find the first element matched by the given selector. Equivalent to calling
516
`querySelector()` on the test root element.
617
718
@public
819
@param {string} selector the selector to search for
9-
@return {Element} matched element or null
20+
@return {Element | null} matched element or null
21+
22+
@example
23+
<caption>
24+
Find all of the elements matching '.my-selector'.
25+
</caption>
26+
findAll('.my-selector');
27+
1028
*/
1129
export default function find(selector: string): Element | null {
1230
if (!selector) {

addon-test-support/@ember/test-helpers/dom/get-root-element.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import { isDocument, isElement } from './-target';
66
77
@public
88
@returns {Element} the root element
9+
10+
@example
11+
<caption>
12+
Getting the root element of the application and checking that it is equal
13+
to the element with id 'ember-testing'.
14+
</caption>
15+
assert.equal(getRootElement(), document.querySelector('#ember-testing'));
916
*/
1017
export default function getRootElement(): Element | Document {
1118
let context = getContext();

0 commit comments

Comments
 (0)