1 | // Type definitions for ember-qunit 5.0
|
2 | // Project: https://github.com/emberjs/ember-qunit#readme
|
3 | // Definitions by: Dan Freeman <https://github.com/dfreeman>
|
4 | // Chris Krycho <https://github.com/chriskrycho>
|
5 | // James C. Davis <https://github.com/jamescdavis>
|
6 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
7 | // Minimum TypeScript Version: 4.4
|
8 |
|
9 | import EmberTestAdapter from '@ember/test/adapter';
|
10 | import EmberResolver from 'ember-resolver';
|
11 | import { TestContext } from '@ember/test-helpers';
|
12 |
|
13 | /**
|
14 | * Sets a Resolver globally which will be used to look up objects from each test's container.
|
15 | */
|
16 | export function setResolver(resolver: EmberResolver): void;
|
17 |
|
18 | /**
|
19 | * Options for configuring the test runner. Normally, you will not need to
|
20 | * customize this. It is exported primarily so that end user app code can name
|
21 | * it when passing it back to the framework.
|
22 | */
|
23 | export interface SetupTestOptions {
|
24 | /**
|
25 | * The resolver to use when instantiating container-managed entities in the test.
|
26 | */
|
27 | resolver?: EmberResolver | undefined;
|
28 | }
|
29 |
|
30 | /**
|
31 | * Sets up acceptance tests.
|
32 | *
|
33 | * The `setupApplicationTest` function is used for all acceptance tests. It
|
34 | * is invoked in the callback scope of a QUnit module (aka "nested module").
|
35 | *
|
36 | * Once invoked, all subsequent hooks.beforeEach and test invocations will
|
37 | * have access to the following:
|
38 | * * `this.owner` - the owner object that been set on the test context.
|
39 | * * `this.pauseTest` and `this.resumeTest` - allow easy pausing/resuming of tests.
|
40 | * * `this.element` which returns the DOM element representing the application's root element.
|
41 | */
|
42 | export function setupApplicationTest(hooks: NestedHooks, options?: SetupTestOptions): void;
|
43 |
|
44 | /**
|
45 | * Sets up tests that need to render snippets of templates.
|
46 | *
|
47 | * The setupRenderingTest method is used for tests that need to render
|
48 | * snippets of templates. It is also invoked in the callback scope of a
|
49 | * QUnit module (aka "nested module").
|
50 | *
|
51 | * Once invoked, all subsequent hooks.beforeEach and test invocations will
|
52 | * have access to the following:
|
53 | * * All of the methods / properties listed for `setupTest`
|
54 | * * this.render(...) - Renders the provided template snippet returning a
|
55 | * promise that resolves once rendering has completed
|
56 | * * An importable render function that de-sugars into this.render will be
|
57 | * the default output of blueprints
|
58 | * * this.element - Returns the native DOM element representing the element
|
59 | * that was rendered via this.render
|
60 | * * this.$(...) - When jQuery is present, executes a jQuery selector with
|
61 | * the current this.element as its root
|
62 | */
|
63 | export function setupRenderingTest(hooks: NestedHooks, options?: SetupTestOptions): void;
|
64 |
|
65 | /**
|
66 | * Sets up tests that do not need to render snippets of templates.
|
67 | *
|
68 | * The `setupTest` method is used for all types of tests except for those
|
69 | * that need to render snippets of templates. It is invoked in the callback
|
70 | * scope of a QUnit module (aka "nested module").
|
71 | *
|
72 | * Once invoked, all subsequent hooks.beforeEach and test invocations will
|
73 | * have access to the following:
|
74 | * * this.owner - This exposes the standard "owner API" for the test environment.
|
75 | * * this.set / this.setProperties - Allows setting values on the test context.
|
76 | * * this.get / this.getProperties - Retrieves values from the test context.
|
77 | */
|
78 | export function setupTest(hooks: NestedHooks, options?: SetupTestOptions): void;
|
79 |
|
80 | export class QUnitAdapter extends EmberTestAdapter {}
|
81 |
|
82 | export { module, test, skip, only, todo } from 'qunit';
|
83 |
|
84 | interface QUnitStartOptions {
|
85 | /**
|
86 | * If `false` tests will not be loaded automatically.
|
87 | */
|
88 | loadTests?: boolean | undefined;
|
89 |
|
90 | /**
|
91 | * If `false` the test container will not be setup based on `devmode`,
|
92 | * `dockcontainer`, or `nocontainer` URL params.
|
93 | */
|
94 | setupTestContainer?: boolean | undefined;
|
95 |
|
96 | /**
|
97 | * If `false` tests will not be automatically started (you must run
|
98 | * `QUnit.start()` to kick them off).
|
99 | */
|
100 | startTests?: boolean | undefined;
|
101 |
|
102 | /**
|
103 | * If `false` the default Ember.Test adapter will not be updated.
|
104 | */
|
105 | setupTestAdapter?: boolean | undefined;
|
106 |
|
107 | /**
|
108 | * `false` opts out of the default behavior of setting `Ember.testing`
|
109 | * to `true` before all tests and back to `false` after each test will.
|
110 | */
|
111 | setupEmberTesting?: boolean | undefined;
|
112 |
|
113 | /**
|
114 | * If `false` validation of `Ember.onerror` will be disabled.
|
115 | */
|
116 | setupEmberOnerrorValidation?: boolean | undefined;
|
117 |
|
118 | /**
|
119 | * If `false` test isolation validation will be disabled.
|
120 | */
|
121 | setupTestIsolationValidation?: boolean | undefined;
|
122 | }
|
123 |
|
124 | export function start(options?: QUnitStartOptions): void;
|
125 |
|
126 | declare global {
|
127 | // NOTE: disables `no-unnecessary-generics` inline because, unfortunately,
|
128 | // the design of Ember's test tooling (and indeed *QUnit's* test system)
|
129 | // requires that we allow users to update the type of the context of the
|
130 | // test. This is indeed strictly *wrong*! However, changing it will require
|
131 | // changing how Ember handles testing. See [the PR][pr] for further details.
|
132 | //
|
133 | // [pr]: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/56494
|
134 |
|
135 | interface NestedHooks {
|
136 | /**
|
137 | * Runs after the last test. If additional tests are defined after the
|
138 | * module's queue has emptied, it will not run this hook again.
|
139 | */
|
140 | // tslint:disable-next-line no-unnecessary-generics
|
141 | after<TC extends TestContext>(fn: (this: TC, assert: Assert) => void | Promise<void>): void;
|
142 |
|
143 | /**
|
144 | * Runs after each test.
|
145 | */
|
146 | // tslint:disable-next-line no-unnecessary-generics
|
147 | afterEach<TC extends TestContext>(fn: (this: TC, assert: Assert) => void | Promise<void>): void;
|
148 |
|
149 | /**
|
150 | * Runs before the first test.
|
151 | */
|
152 | // tslint:disable-next-line no-unnecessary-generics
|
153 | before<TC extends TestContext>(fn: (this: TC, assert: Assert) => void | Promise<void>): void;
|
154 |
|
155 | /**
|
156 | * Runs before each test.
|
157 | */
|
158 | // tslint:disable-next-line no-unnecessary-generics
|
159 | beforeEach<TC extends TestContext>(fn: (this: TC, assert: Assert) => void | Promise<void>): void;
|
160 | }
|
161 |
|
162 | interface QUnit {
|
163 | /**
|
164 | * Add a test to run.
|
165 | *
|
166 | * Add a test to run using `QUnit.test()`.
|
167 | *
|
168 | * The `assert` argument to the callback contains all of QUnit's assertion
|
169 | * methods. Use this argument to call your test assertions.
|
170 | *
|
171 | * `QUnit.test()` can automatically handle the asynchronous resolution of a
|
172 | * Promise on your behalf if you return a thenable Promise as the result of
|
173 | * your callback function.
|
174 | *
|
175 | * @param name Title of unit being tested
|
176 | * @param callback Function to close over assertions
|
177 | */
|
178 | // tslint:disable-next-line no-unnecessary-generics
|
179 | test<TC extends TestContext>(name: string, callback: (this: TC, assert: Assert) => void | Promise<void>): void;
|
180 |
|
181 | /**
|
182 | * Adds a test to exclusively run, preventing all other tests from running.
|
183 | *
|
184 | * Use this method to focus your test suite on a specific test. QUnit.only
|
185 | * will cause any other tests in your suite to be ignored.
|
186 | *
|
187 | * Note, that if more than one QUnit.only is present only the first instance
|
188 | * will run.
|
189 | *
|
190 | * This is an alternative to filtering tests to run in the HTML reporter. It
|
191 | * is especially useful when you use a console reporter or in a codebase
|
192 | * with a large set of long running tests.
|
193 | *
|
194 | * @param name Title of unit being tested
|
195 | * @param callback Function to close over assertions
|
196 | */
|
197 | // tslint:disable-next-line no-unnecessary-generics
|
198 | only<TC extends TestContext>(name: string, callback: (this: TC, assert: Assert) => void | Promise<void>): void;
|
199 |
|
200 | /**
|
201 | * Use this method to test a unit of code which is still under development (in a “todo” state).
|
202 | * The test will pass as long as one failing assertion is present.
|
203 | *
|
204 | * If all assertions pass, then the test will fail signaling that `QUnit.todo` should
|
205 | * be replaced by `QUnit.test`.
|
206 | *
|
207 | * @param name Title of unit being tested
|
208 | * @param callback Function to close over assertions
|
209 | */
|
210 | // tslint:disable-next-line no-unnecessary-generics
|
211 | todo<TC extends TestContext>(name: string, callback: (this: TC, assert: Assert) => void | Promise<void>): void;
|
212 |
|
213 | /**
|
214 | * Adds a test like object to be skipped.
|
215 | *
|
216 | * Use this method to replace QUnit.test() instead of commenting out entire
|
217 | * tests.
|
218 | *
|
219 | * This test's prototype will be listed on the suite as a skipped test,
|
220 | * ignoring the callback argument and the respective global and module's
|
221 | * hooks.
|
222 | *
|
223 | * @param name Title of unit being tested
|
224 | * @param callback Function to close over assertions
|
225 | */
|
226 | // tslint:disable-next-line no-unnecessary-generics
|
227 | skip<TC extends TestContext>(name: string, callback?: (this: TC, assert: Assert) => void | Promise<void>): void;
|
228 | }
|
229 | }
|
230 |
|
\ | No newline at end of file |