Skip to content

Commit

Permalink
Upgrade expect-type and fix issues the new version reveals
Browse files Browse the repository at this point in the history
(cherry picked from commit 3f42108)
  • Loading branch information
gitKrystan authored and chriskrycho committed Dec 15, 2022
1 parent d537923 commit bae5e33
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 42 deletions.
42 changes: 20 additions & 22 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Emulating filling an input with text using `fillIn`
fillIn('input', 'hello world');
```

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

### focus

Expand Down Expand Up @@ -376,7 +376,7 @@ Emulating tapping a button using `tap`
tap('button');
```

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

### triggerEvent

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

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

```javascript
triggerEvent(
Expand All @@ -406,8 +406,8 @@ triggerEvent(

Using `triggerEvent` to upload a dropped file

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],
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].
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],
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].

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

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

#### Parameters
Expand Down Expand Up @@ -596,7 +596,7 @@ while *not* settled (e.g. "loading" or "pending" states).

#### Parameters

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

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

#### Parameters

* `context` **[Object][72]** the context to setup for rendering
* `context` **TestContext** the context to setup for rendering

Returns **[Promise][66]<[Object][72]>** resolves with the context that was setup
Returns **[Promise][66]\<RenderingTestContext>** resolves with the context that was setup

### getApplication

Expand Down Expand Up @@ -906,7 +906,7 @@ everything is on fire...

#### Parameters

* `callback` **[Function][79]** the callback to validate (optional, default `Ember.onerror`)
* `callback` **[Function][78]** the callback to validate (optional, default `Ember.onerror`)

#### Examples

Expand All @@ -931,7 +931,7 @@ without an `onError` argument.

#### Parameters

* `onError` **[Function][79]** the onError function to be set on Ember.onerror
* `onError` **[Function][78]** the onError function to be set on Ember.onerror

#### Examples

Expand Down Expand Up @@ -1018,7 +1018,7 @@ Returns deprecations which have occured so far for a the current test context

### Parameters

* `callback` **[Function][79]?** The callback that when executed will have its DeprecationFailure recorded
* `callback` **[Function][78]?** The callback that when executed will have its DeprecationFailure recorded

### Examples

Expand Down Expand Up @@ -1076,7 +1076,7 @@ Returns warnings which have occured so far for a the current test context

### Parameters

* `callback` **[Function][79]?** The callback that when executed will have its warnings recorded
* `callback` **[Function][78]?** The callback that when executed will have its warnings recorded

### Examples

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

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

[73]: https://developer.mozilla.org/docs/Web/API/Event

[74]: https://developer.mozilla.org/en-US/docs/Web/API/Blob
[73]: https://developer.mozilla.org/en-US/docs/Web/API/Blob

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

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

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

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

[79]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
[78]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
7 changes: 2 additions & 5 deletions addon-test-support/@ember/test-helpers/dom/fill-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ registerHook('fillIn', 'start', (target: Target, text: string) => {
@public
@param {string|Element} target the element or selector to enter text into
@param {string} text the text to fill into the target element
@return {Promise<Element | void>} resolves when the application is settled
@return {Promise<void>} resolves when the application is settled
@example
<caption>
Expand All @@ -30,10 +30,7 @@ registerHook('fillIn', 'start', (target: Target, text: string) => {
fillIn('input', 'hello world');
*/
export default function fillIn(
target: Target,
text: string
): Promise<Element | void> {
export default function fillIn(target: Target, text: string): Promise<void> {
return Promise.resolve()
.then(() => runHooks('fillIn', 'start', target, text))
.then(() => {
Expand Down
4 changes: 2 additions & 2 deletions addon-test-support/@ember/test-helpers/dom/tap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ registerHook('tap', 'start', (target: Target) => {
@public
@param {string|Element} target the element or selector to tap on
@param {Object} options the options to be merged into the touch events
@return {Promise<Event | Event[] | void>} resolves when settled
@return {Promise<void>} resolves when settled
@example
<caption>
Expand All @@ -57,7 +57,7 @@ registerHook('tap', 'start', (target: Target) => {
export default function tap(
target: Target,
options: TouchEventInit = {}
): Promise<Event | Event[] | void> {
): Promise<void> {
return Promise.resolve()
.then(() => {
return runHooks('tap', 'start', target, options);
Expand Down
1 change: 1 addition & 0 deletions addon-test-support/@ember/test-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export {
render,
clearRender,
} from './setup-rendering-context';
export type { RenderingTestContext } from './setup-rendering-context';
export { default as rerender } from './rerender';
export {
default as setupApplicationContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import settled from './settled';
import { hbs, TemplateFactory } from 'ember-cli-htmlbars';
import getRootElement from './dom/get-root-element';
import { Owner } from './build-owner';
import getTestMetadata, { TestMetadata } from './test-metadata';
import getTestMetadata from './test-metadata';
import { assert, deprecate } from '@ember/debug';
import { runHooks } from './-internal/helper-hooks';
import hasEmberVersion from './has-ember-version';
Expand All @@ -22,7 +22,6 @@ import { macroCondition, dependencySatisfies } from '@embroider/macros';
import { ComponentRenderMap, SetUsage } from './setup-context';
import { ensureSafeComponent } from '@embroider/util';
import type { ComponentInstance } from '@glimmer/interfaces';
import ViewMixin from '@ember/component/-private/view-mixin';

const OUTLET_TEMPLATE = hbs`{{outlet}}`;
const EMPTY_TEMPLATE = hbs``;
Expand All @@ -32,8 +31,6 @@ export interface RenderingTestContext extends TestContext {
render(template: TemplateFactory): Promise<void>;
clearRender(): Promise<void>;

$?(selector: string): any;

element: Element | Document;
}

Expand Down Expand Up @@ -271,8 +268,8 @@ export function clearRender(): Promise<void> {
element).
@public
@param {Object} context the context to setup for rendering
@returns {Promise<Object>} resolves with the context that was setup
@param {TestContext} context the context to setup for rendering
@returns {Promise<RenderingTestContext>} resolves with the context that was setup
*/
export default function setupRenderingContext(
context: TestContext
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"eslint-plugin-disable-features": "^0.1.3",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"expect-type": "^0.13.0",
"expect-type": "^0.15.0",
"fs-extra": "^10.0.0",
"latest-version": "^5.0.0",
"loader.js": "^4.7.0",
Expand Down
5 changes: 3 additions & 2 deletions type-tests/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
focus,
scrollTo,
select,
tab,
tap,
triggerEvent,
triggerKeyEvent,
Expand Down Expand Up @@ -45,6 +46,7 @@ import {
unsetContext,
teardownContext,
setupRenderingContext,
RenderingTestContext,
getApplication,
setApplication,
setupApplicationContext,
Expand All @@ -63,7 +65,6 @@ import {
DebugInfo as InternalDebugInfo,
DeprecationFailure,
Warning,
tab,
} from '@ember/test-helpers';
import { ComponentInstance } from '@glimmer/interfaces';
import { Owner } from '@ember/test-helpers/build-owner';
Expand Down Expand Up @@ -219,7 +220,7 @@ expectTypeOf(teardownContext).toEqualTypeOf<
) => Promise<void>
>();
expectTypeOf(setupRenderingContext).toEqualTypeOf<
(context: TestContext) => Promise<void>
(context: TestContext) => Promise<RenderingTestContext>
>();
expectTypeOf(getApplication).toEqualTypeOf<() => Application | undefined>();
expectTypeOf(setApplication).toEqualTypeOf<
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6470,10 +6470,10 @@ expand-tilde@^2.0.0, expand-tilde@^2.0.2:
dependencies:
homedir-polyfill "^1.0.1"

expect-type@^0.13.0:
version "0.13.0"
resolved "https://registry.yarnpkg.com/expect-type/-/expect-type-0.13.0.tgz#916646a7a73f3ee77039a634ee9035efe1876eb2"
integrity sha512-CclevazQfrqo8EvbLPmP7osnb1SZXkw47XPPvUUpeMz4HuGzDltE7CaIt3RLyT9UQrwVK/LDn+KVcC0hcgjgDg==
expect-type@^0.15.0:
version "0.15.0"
resolved "https://registry.yarnpkg.com/expect-type/-/expect-type-0.15.0.tgz#89f75e22c88554844ea2b2faf4ef5fc2e579d3b5"
integrity sha512-yWnriYB4e8G54M5/fAFj7rCIBiKs1HAACaY13kCz6Ku0dezjS9aMcfcdVK2X8Tv2tEV1BPz/wKfQ7WA4S/d8aA==

express@^4.10.7, express@^4.17.1:
version "4.18.2"
Expand Down

0 comments on commit bae5e33

Please sign in to comment.