UNPKG

3.14 kBTypeScriptView Raw
1declare module 'ember-testing/lib/test/helpers' {
2 import type { AnyFn } from '@ember/-internals/utility-types';
3 import type Application from '@ember/application';
4 export const helpers: Record<
5 string,
6 {
7 method: AnyFn;
8 meta: {
9 wait: boolean;
10 };
11 }
12 >;
13 /**
14 @module @ember/test
15 */
16 /**
17 `registerHelper` is used to register a test helper that will be injected
18 when `App.injectTestHelpers` is called.
19
20 The helper method will always be called with the current Application as
21 the first parameter.
22
23 For example:
24
25 ```javascript
26 import { registerHelper } from '@ember/test';
27 import { run } from '@ember/runloop';
28
29 registerHelper('boot', function(app) {
30 run(app, app.advanceReadiness);
31 });
32 ```
33
34 This helper can later be called without arguments because it will be
35 called with `app` as the first parameter.
36
37 ```javascript
38 import Application from '@ember/application';
39
40 App = Application.create();
41 App.injectTestHelpers();
42 boot();
43 ```
44
45 @public
46 @for @ember/test
47 @static
48 @method registerHelper
49 @param {String} name The name of the helper method to add.
50 @param {Function} helperMethod
51 @param options {Object}
52 */
53 export function registerHelper(
54 name: string,
55 helperMethod: (app: Application, ...args: any[]) => unknown
56 ): void;
57 /**
58 `registerAsyncHelper` is used to register an async test helper that will be injected
59 when `App.injectTestHelpers` is called.
60
61 The helper method will always be called with the current Application as
62 the first parameter.
63
64 For example:
65
66 ```javascript
67 import { registerAsyncHelper } from '@ember/test';
68 import { run } from '@ember/runloop';
69
70 registerAsyncHelper('boot', function(app) {
71 run(app, app.advanceReadiness);
72 });
73 ```
74
75 The advantage of an async helper is that it will not run
76 until the last async helper has completed. All async helpers
77 after it will wait for it complete before running.
78
79
80 For example:
81
82 ```javascript
83 import { registerAsyncHelper } from '@ember/test';
84
85 registerAsyncHelper('deletePost', function(app, postId) {
86 click('.delete-' + postId);
87 });
88
89 // ... in your test
90 visit('/post/2');
91 deletePost(2);
92 visit('/post/3');
93 deletePost(3);
94 ```
95
96 @public
97 @for @ember/test
98 @method registerAsyncHelper
99 @param {String} name The name of the helper method to add.
100 @param {Function} helperMethod
101 @since 1.2.0
102 */
103 export function registerAsyncHelper(name: string, helperMethod: AnyFn): void;
104 /**
105 Remove a previously added helper method.
106
107 Example:
108
109 ```javascript
110 import { unregisterHelper } from '@ember/test';
111
112 unregisterHelper('wait');
113 ```
114
115 @public
116 @method unregisterHelper
117 @static
118 @for @ember/test
119 @param {String} name The helper to remove.
120 */
121 export function unregisterHelper(name: string): void;
122}