UNPKG

4.01 kBTypeScriptView Raw
1// Type definitions for ember-test-helpers 1.0
2// Project: https://github.com/emberjs/ember-test-helpers#readme
3// Definitions by: Derek Wickern <https://github.com/dwickern>
4// Mike North <https://github.com/mike-north>
5// Chris Krycho <https://github.com/chriskrycho>
6// James C. Davis <https://github.com/jamescdavis>
7// Krystan HuffMenne <https://github.com/gitKrystan>
8// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
9// TypeScript Version: 3.7
10
11// NOTE: These types apply to ember-test-helper v0.7. The major
12// version had to be bumped for SemVer due to a breaking change
13// in TypeScript 3.1
14//
15// In the future, we'll use another versioning strategy that
16// provides safety from breaking changes without bumping the major
17// version number
18
19/// <reference types="jquery" />
20
21declare module 'ember-test-helpers' {
22 import Ember from 'ember';
23 import { TemplateFactory } from 'htmlbars-inline-precompile';
24 import RSVP from 'rsvp';
25
26 interface ModuleCallbacks {
27 integration?: boolean | undefined;
28 unit?: boolean | undefined;
29 needs?: string[] | undefined;
30
31 beforeSetup?(assert?: any): void;
32 setup?(assert?: any): void;
33 teardown?(assert?: any): void;
34 afterTeardown?(assert?: any): void;
35
36 [key: string]: any;
37 }
38
39 interface TestContext {
40 get(key: string): any;
41 getProperties<K extends string>(...keys: K[]): Pick<any, K>;
42 set<V>(key: string, value: V): V;
43 setProperties<P extends { [key: string]: any }>(hash: P): P;
44 on(actionName: string, handler: (this: TestContext, ...args: any[]) => any): void;
45 send(actionName: string): void;
46 $: JQueryStatic;
47 subject(options?: {}): any;
48 render(template?: string | string[] | TemplateFactory): Promise<void>;
49 clearRender(): void;
50 registry: Ember.Registry;
51 container: Ember.Container;
52 dispatcher: Ember.EventDispatcher;
53 application: Ember.Application;
54 register(fullName: string, factory: any): void;
55 factory(fullName: string): any;
56 inject: {
57 controller(name: string, options?: { as: string }): any;
58 service(name: string, options?: { as: string }): any;
59 };
60 owner: Ember.ApplicationInstance & {
61 factoryFor(fullName: string, options?: {}): any;
62 };
63 pauseTest(): Promise<void>;
64 resumeTest(): void;
65 element: Element;
66 }
67
68 class TestModule {
69 constructor(name: string, callbacks?: ModuleCallbacks);
70 constructor(name: string, description?: string, callbacks?: ModuleCallbacks);
71
72 name: string;
73 subjectName: string;
74 description: string;
75 isIntegration: boolean;
76 callbacks: ModuleCallbacks;
77 context: TestContext;
78 resolver: Ember.Resolver;
79
80 setup(assert?: any): RSVP.Promise<void>;
81 teardown(assert?: any): RSVP.Promise<void>;
82 getContext(): TestContext;
83 setContext(context: TestContext): void;
84 }
85
86 class TestModuleForAcceptance extends TestModule {}
87 class TestModuleForIntegration extends TestModule {}
88 class TestModuleForComponent extends TestModule {}
89 class TestModuleForModel extends TestModule {}
90
91 function getContext(): TestContext | undefined;
92 function setContext(context: TestContext): void;
93 function unsetContext(): void;
94 function setResolver(resolver: Ember.Resolver): void;
95}
96
97declare module 'ember-test-helpers/wait' {
98 import RSVP from 'rsvp';
99
100 interface WaitOptions {
101 waitForTimers?: boolean | undefined;
102 waitForAJAX?: boolean | undefined;
103 waitForWaiters?: boolean | undefined;
104 }
105
106 export default function wait(options?: WaitOptions): RSVP.Promise<void>;
107}
108
109declare module 'ember-test-helpers/has-ember-version' {
110 export default function hasEmberVersion(major: number, minor: number): boolean;
111}