forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jasmine-jquery.d.ts
388 lines (341 loc) · 13.7 KB
/
jasmine-jquery.d.ts
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
// Type definitions for Jasmine-JQuery 1.5.8
// Project: https://github.com/velesin/jasmine-jquery
// Definitions by: Gregor Stamac <https://github.com/gstamac/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../jasmine/jasmine.d.ts"/>
/// <reference path="../jquery/jquery.d.ts"/>
declare function sandbox(attributes?: any): string;
declare function readFixtures(...uls: string[]): string;
declare function preloadFixtures(...uls: string[]) : void;
declare function loadFixtures(...uls: string[]): void;
declare function appendLoadFixtures(...uls: string[]): void;
declare function setFixtures(html: string): string;
declare function appendSetFixtures(html: string) : void;
declare function preloadStyleFixtures(...uls: string[]) : void;
declare function loadStyleFixtures(...uls: string[]) : void;
declare function appendLoadStyleFixtures(...uls: string[]) : void;
declare function setStyleFixtures(html: string) : void;
declare function appendSetStyleFixtures(html: string) : void;
declare function loadJSONFixtures(...uls: string[]): jasmine.JSONFixtures;
declare function getJSONFixture(url: string): any;
declare function spyOnEvent(selector: string, eventName: string): jasmine.JQueryEventSpy;
declare module jasmine {
function spiedEventsKey(selector: JQuery, eventName: string): string;
function getFixtures(): Fixtures;
function getStyleFixtures(): StyleFixtures;
function getJSONFixtures(): JSONFixtures;
interface Fixtures {
fixturesPath: string;
containerId: string;
set(html: string): string;
appendSet(html: string): void;
preload(...uls: string[]): void;
load(...uls: string[]): void;
appendLoad(...uls: string[]): void;
read(...uls: string[]): string;
clearCache(): void;
cleanUp(): void;
sandbox(attributes?: any): string;
createContainer_(html: string) : string;
addToContainer_(html: string): void;
getFixtureHtml_(url: string): string;
loadFixtureIntoCache_(relativeUrl: string): void;
makeFixtureUrl_(relativeUrl: string): string;
proxyCallTo_(methodName: string, passedArguments: any): any;
}
interface StyleFixtures {
fixturesPath: string;
set(html: string): string;
appendSet(html: string): void;
preload(...uls: string[]) : void;
load(...uls: string[]) : void;
appendLoad(...uls: string[]) : void;
read_(...uls: string[]): string;
clearCache() : void;
cleanUp() : void;
createStyle_(html: string) : void;
getFixtureHtml_(url: string): string;
loadFixtureIntoCache_(relativeUrl: string) : void;
makeFixtureUrl_(relativeUrl: string): string;
proxyCallTo_(methodName: string, passedArguments: any): any;
}
interface JSONFixtures {
fixturesPath: string;
load(...uls: string[]): void;
read(...uls: string[]): string;
clearCache(): void;
getFixtureData_(url: string): any;
loadFixtureIntoCache_(relativeUrl: string): void;
proxyCallTo_(methodName: string, passedArguments: any): any;
}
interface Matchers {
/**
* Check if DOM element has class.
*
* @param className Name of the class to check.
*
* @example
* // returns true
* expect($('<div class="some-class"></div>')).toHaveClass("some-class")
*/
toHaveClass(className: string): boolean;
/**
* Check if DOM element has the given CSS properties.
*
* @param css Object containing the properties (and values) to check.
*
* @example
* // returns true
* expect($('<div style="display: none; margin: 10px;"></div>')).toHaveCss({display: "none", margin: "10px"})
*
* @example
* // returns true
* expect($('<div style="display: none; margin: 10px;"></div>')).toHaveCss({margin: "10px"})
*/
toHaveCss(css: any): boolean;
/**
* Checks if DOM element is visible.
* Elements are considered visible if they consume space in the document. Visible elements have a width or height that is greater than zero.
*/
toBeVisible(): boolean;
/**
* Check if DOM element is hidden.
* Elements can be hidden for several reasons:
* - They have a CSS display value of none ;
* - They are form elements with type equal to hidden.
* - Their width and height are explicitly set to 0.
* - An ancestor element is hidden, so the element is not shown on the page.
*/
toBeHidden(): boolean;
/**
* Only for tags that have checked attribute
*
* @example
* // returns true
* expect($('<option selected="selected"></option>')).toBeSelected()
*/
toBeSelected(): boolean;
/**
* Only for tags that have checked attribute
* @example
* // returns true
* expect($('<input type="checkbox" checked="checked"/>')).toBeChecked()
*/
toBeChecked(): boolean;
/**
* Checks for child DOM elements or text
*/
toBeEmpty(): boolean;
/**
* Checks if element exists in or out the DOM.
*/
toExist(): boolean;
/**
* Checks if array has the given length.
*
* @param length Expected length
*/
toHaveLength(length: number): boolean;
/**
* Check if DOM element contains an attribute and, optionally, if the value of the attribute is equal to the expected one.
*
* @param attributeName Name of the attribute to check
* @param expectedAttributeValue Expected attribute value
*/
toHaveAttr(attributeName: string, expectedAttributeValue? : any): boolean;
/**
* Check if DOM element contains a property and, optionally, if the value of the property is equal to the expected one.
*
* @param propertyName Property name to check
* @param expectedPropertyValue Expected property value
*/
toHaveProp(propertyName: string, expectedPropertyValue? : any): boolean;
/**
* Check if DOM element has the given Id
*
* @param Id Expected identifier
*/
toHaveId(id: string): boolean;
/**
* Check if DOM element has the specified HTML.
*
* @example
* // returns true
* expect($('<div><span></span></div>')).toHaveHtml('<span></span>')
*/
toHaveHtml(html: string): boolean;
/**
* Check if DOM element contains the specified HTML.
*
* @example
* // returns true
* expect($('<div><ul></ul><h1>header</h1></div>')).toContainHtml('<ul></ul>')
*/
//toContainHtml(html: string): boolean;
/**
* Check if DOM element has the given Text.
* @param text Accepts a string or regular expression
*
* @example
* // returns true
* expect($('<div>some text</div>')).toHaveText('some text')
*/
toHaveText(text: string): boolean;
/**
* Check if DOM element contains the specified text.
*
* @example
* // returns true
* expect($('<div><ul></ul><h1>header</h1></div>')).toContainText('header')
*/
//toContainText(text: string): boolean;
/**
* Check if DOM element has the given value.
* This can only be applied for element on with jQuery val() can be called.
*
* @example
* // returns true
* expect($('<input type="text" value="some text"/>')).toHaveValue('some text')
*/
toHaveValue(value : string): boolean;
/**
* Check if DOM element has the given data.
* This can only be applied for element on with jQuery data(key) can be called.
*
*/
toHaveData(key : string, expectedValue : string): boolean;
toBe(selector: JQuery): boolean;
/**
* Check if DOM element is matched by the given selector.
*
* @example
* // returns true
* expect($('<div><span class="some-class"></span></div>')).toContain('some-class')
*/
toContain(selector: JQuery): boolean;
/**
* Check if DOM element exists inside the given parent element.
*
* @example
* // returns true
* expect($('<div><span class="some-class"></span></div>')).toContainElement('span.some-class')
*/
toContainElement(selector: string): boolean;
/**
* Check to see if the set of matched elements matches the given selector
*
* @example
* expect($('<span></span>').addClass('js-something')).toBeMatchedBy('.js-something')
*
* @returns {Boolean} true if DOM contains the element
*/
toBeMatchedBy(selector: string): boolean;
/**
* Only for tags that have disabled attribute
* @example
* // returns true
* expect('<input type="submit" disabled="disabled"/>').toBeDisabled()
*/
toBeDisabled(): boolean;
/**
* Check if DOM element is focused
* @example
* // returns true
* expect($('<input type="text" />').focus()).toBeFocused()
*/
toBeFocused(): boolean;
/**
* Checks if DOM element handles event.
*
* @example
* // returns true
* expect($form).toHandle("submit")
*/
toHandle(eventName: string): boolean;
/**
* Assigns a callback to an event of the DOM element.
*
* @param eventName Name of the event to assign the callback to.
* @param eventHandler Callback function to be assigned.
*
* @example
* expect($form).toHandleWith("submit", yourSubmitCallback)
*/
toHandleWith(eventName: string, eventHandler : JQueryCallback): boolean;
/**
* Checks if event was triggered.
*/
toHaveBeenTriggered(): boolean;
/**
* Checks if the event has been triggered on selector.
* @param selector Selector that should have triggered the event.
*/
toHaveBeenTriggeredOn(selector: string): boolean;
/**
* Checks if the event has been triggered on selector.
* @param selector Selector that should have triggered the event.
* @param args Extra arguments to be passed to jQuery events functions.
*/
toHaveBeenTriggeredOnAndWith(selector: string, ...args: any[]): boolean;
/**
* Checks if event propagation has been prevented.
*/
toHaveBeenPrevented(): boolean;
/**
* Checks if event propagation has been prevented on element with selector.
*
* @param selector Selector that should have prevented the event.
*/
toHaveBeenPreventedOn(selector: string): boolean;
/**
* Checks if event propagation has been stopped.
*
* @example
* // returns true
* var spyEvent = spyOnEvent('#some_element', 'click')
* $('#some_element').click(function (event){event.stopPropagation();})
* $('#some_element').click()
* expect(spyEvent).toHaveBeenStopped()
*/
toHaveBeenStopped(): boolean;
/**
* Checks if event propagation has been stopped by an element with the given selector.
* @param selector Selector of the element that should have stopped the event propagation.
*
* @example
* // returns true
* $('#some_element').click(function (event){event.stopPropagation();})
* $('#some_element').click()
* expect('click').toHaveBeenStoppedOn('#some_element')
*/
toHaveBeenStoppedOn(selector: string): boolean;
/**
* Checks to see if the matched element is attached to the DOM.
* @example
* expect($('#id-name')[0]).toBeInDOM()
*/
toBeInDOM(): boolean;
}
interface JQueryEventSpy {
selector: string;
eventName: string;
handler(eventObject: JQueryEventObject): any;
reset(): any;
}
interface JasmineJQuery {
browserTagCaseIndependentHtml(html: string): string;
elementToString(element: JQuery): string;
matchersClass: any;
events: JasmineJQueryEvents;
}
interface JasmineJQueryEvents {
spyOn(selector: string, eventName: string): JQueryEventSpy;
args(selector: string, eventName: string): any;
wasTriggered(selector: string, eventName: string): boolean;
wasTriggeredWith(selector: string, eventName: string, expectedArgs: any, env: jasmine.Env): boolean;
wasPrevented(selector: string, eventName: string): boolean;
wasStopped(selector: string, eventName: string): boolean;
cleanUp() : void;
}
var JQuery: JasmineJQuery;
}