forked from emberjs/ember-test-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteardown-context.ts
More file actions
51 lines (41 loc) · 1.38 KB
/
Copy pathteardown-context.ts
File metadata and controls
51 lines (41 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import type { TestContext } from './setup-context';
import Ember from 'ember';
import { unsetContext } from './setup-context.ts';
import settled, { _teardownAJAXHooks } from './settled.ts';
import { _cleanupOnerror } from './setup-onerror.ts';
import { destroy } from '@ember/destroyable';
export interface TeardownContextOptions {
waitForSettled?: boolean | undefined;
}
/**
Used by test framework addons to tear down the provided context after testing is completed.
Responsible for:
- un-setting the "global testing context" (`unsetContext`)
- destroy the contexts owner object
- remove AJAX listeners
@public
@param {Object} context the context to setup
@param {Object} [options] options used to override defaults
@param {boolean} [options.waitForSettled=true] should the teardown wait for `settled()`ness
@returns {Promise<void>} resolves when settled
*/
export default function teardownContext(
context: TestContext,
{ waitForSettled = true }: TeardownContextOptions = {},
): Promise<void> {
return Promise.resolve()
.then(() => {
_cleanupOnerror(context);
_teardownAJAXHooks();
// SAFETY: this is intimate API *designed* for us to override.
(Ember as any).testing = false;
unsetContext();
destroy(context.owner);
})
.finally(() => {
if (waitForSettled) {
return settled();
}
return;
});
}