blob: a09085bdddc19dd633467920474f49eaf4c2fe99 [file] [log] [blame]
Matteo Scandolo5461a7c2017-08-08 13:05:24 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Matteo Scandolofc4b37b2017-02-02 12:18:47 -080019// Generated by typings
20// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/cd4debea25a280da0808d4ff2ca5a4bdb34bd28b/jasmine-jquery/index.d.ts
21declare function sandbox(attributes?: any): string;
22
23declare function readFixtures(...uls: string[]): string;
24declare function preloadFixtures(...uls: string[]) : void;
25declare function loadFixtures(...uls: string[]): void;
26declare function appendLoadFixtures(...uls: string[]): void;
27declare function setFixtures(html: string): string;
28declare function appendSetFixtures(html: string) : void;
29
30declare function preloadStyleFixtures(...uls: string[]) : void;
31declare function loadStyleFixtures(...uls: string[]) : void;
32declare function appendLoadStyleFixtures(...uls: string[]) : void;
33declare function setStyleFixtures(html: string) : void;
34declare function appendSetStyleFixtures(html: string) : void;
35
36declare function loadJSONFixtures(...uls: string[]): jasmine.JSONFixtures;
37declare function getJSONFixture(url: string): any;
38
39declare function spyOnEvent(selector: string, eventName: string): jasmine.JQueryEventSpy;
40
41declare namespace jasmine {
42 function spiedEventsKey(selector: JQuery, eventName: string): string;
43
44 function getFixtures(): Fixtures;
45 function getStyleFixtures(): StyleFixtures;
46 function getJSONFixtures(): JSONFixtures;
47
48 interface Fixtures {
49 fixturesPath: string;
50 containerId: string;
51 set(html: string): string;
52 appendSet(html: string): void;
53 preload(...uls: string[]): void;
54 load(...uls: string[]): void;
55 appendLoad(...uls: string[]): void;
56 read(...uls: string[]): string;
57 clearCache(): void;
58 cleanUp(): void;
59 sandbox(attributes?: any): string;
60 createContainer_(html: string) : string;
61 addToContainer_(html: string): void;
62 getFixtureHtml_(url: string): string;
63 loadFixtureIntoCache_(relativeUrl: string): void;
64 makeFixtureUrl_(relativeUrl: string): string;
65 proxyCallTo_(methodName: string, passedArguments: any): any;
66 }
67
68 interface StyleFixtures {
69 fixturesPath: string;
70 set(html: string): string;
71 appendSet(html: string): void;
72 preload(...uls: string[]) : void;
73 load(...uls: string[]) : void;
74 appendLoad(...uls: string[]) : void;
75 read_(...uls: string[]): string;
76 clearCache() : void;
77 cleanUp() : void;
78 createStyle_(html: string) : void;
79 getFixtureHtml_(url: string): string;
80 loadFixtureIntoCache_(relativeUrl: string) : void;
81 makeFixtureUrl_(relativeUrl: string): string;
82 proxyCallTo_(methodName: string, passedArguments: any): any;
83 }
84
85 interface JSONFixtures {
86 fixturesPath: string;
87 load(...uls: string[]): void;
88 read(...uls: string[]): string;
89 clearCache(): void;
90 getFixtureData_(url: string): any;
91 loadFixtureIntoCache_(relativeUrl: string): void;
92 proxyCallTo_(methodName: string, passedArguments: any): any;
93 }
94
95 interface Matchers {
96 /**
97 * Check if DOM element has class.
98 *
99 * @param className Name of the class to check.
100 *
101 * @example
102 * // returns true
103 * expect($('<div class="some-class"></div>')).toHaveClass("some-class")
104 */
105 toHaveClass(className: string): boolean;
106
107 /**
108 * Check if DOM element has the given CSS properties.
109 *
110 * @param css Object containing the properties (and values) to check.
111 *
112 * @example
113 * // returns true
114 * expect($('<div style="display: none; margin: 10px;"></div>')).toHaveCss({display: "none", margin: "10px"})
115 *
116 * @example
117 * // returns true
118 * expect($('<div style="display: none; margin: 10px;"></div>')).toHaveCss({margin: "10px"})
119 */
120 toHaveCss(css: any): boolean;
121
122 /**
123 * Checks if DOM element is visible.
124 * Elements are considered visible if they consume space in the document. Visible elements have a width or height that is greater than zero.
125 */
126 toBeVisible(): boolean;
127 /**
128 * Check if DOM element is hidden.
129 * Elements can be hidden for several reasons:
130 * - They have a CSS display value of none ;
131 * - They are form elements with type equal to hidden.
132 * - Their width and height are explicitly set to 0.
133 * - An ancestor element is hidden, so the element is not shown on the page.
134 */
135 toBeHidden(): boolean;
136
137 /**
138 * Only for tags that have checked attribute
139 *
140 * @example
141 * // returns true
142 * expect($('<option selected="selected"></option>')).toBeSelected()
143 */
144 toBeSelected(): boolean;
145
146 /**
147 * Only for tags that have checked attribute
148 * @example
149 * // returns true
150 * expect($('<input type="checkbox" checked="checked"/>')).toBeChecked()
151 */
152 toBeChecked(): boolean;
153
154 /**
155 * Checks for child DOM elements or text
156 */
157 toBeEmpty(): boolean;
158
159 /**
160 * Checks if element exists in or out the DOM.
161 */
162 toExist(): boolean;
163
164 /**
165 * Checks if array has the given length.
166 *
167 * @param length Expected length
168 */
169 toHaveLength(length: number): boolean;
170
171 /**
172 * Check if DOM element contains an attribute and, optionally, if the value of the attribute is equal to the expected one.
173 *
174 * @param attributeName Name of the attribute to check
175 * @param expectedAttributeValue Expected attribute value
176 */
177 toHaveAttr(attributeName: string, expectedAttributeValue? : any): boolean;
178
179 /**
180 * Check if DOM element contains a property and, optionally, if the value of the property is equal to the expected one.
181 *
182 * @param propertyName Property name to check
183 * @param expectedPropertyValue Expected property value
184 */
185 toHaveProp(propertyName: string, expectedPropertyValue? : any): boolean;
186
187 /**
188 * Check if DOM element has the given Id
189 *
190 * @param Id Expected identifier
191 */
192 toHaveId(id: string): boolean;
193
194 /**
195 * Check if DOM element has the specified HTML.
196 *
197 * @example
198 * // returns true
199 * expect($('<div><span></span></div>')).toHaveHtml('<span></span>')
200 */
201 toHaveHtml(html: string): boolean;
202
203 /**
204 * Check if DOM element contains the specified HTML.
205 *
206 * @example
207 * // returns true
208 * expect($('<div><ul></ul><h1>header</h1></div>')).toContainHtml('<ul></ul>')
209 */
210 toContainHtml(html: string): boolean;
211
212 /**
213 * Check if DOM element has the given Text.
214 * @param text Accepts a string or regular expression
215 *
216 * @example
217 * // returns true
218 * expect($('<div>some text</div>')).toHaveText('some text')
219 */
220 toHaveText(text: string): boolean;
221 /**
222 * Check if DOM element contains the specified text.
223 *
224 * @example
225 * // returns true
226 * expect($('<div><ul></ul><h1>header</h1></div>')).toContainText('header')
227 */
228 toContainText(text: string): boolean;
229
230 /**
231 * Check if DOM element has the given value.
232 * This can only be applied for element on with jQuery val() can be called.
233 *
234 * @example
235 * // returns true
236 * expect($('<input type="text" value="some text"/>')).toHaveValue('some text')
237 */
238 toHaveValue(value : string): boolean;
239
240 /**
241 * Check if DOM element has the given data.
242 * This can only be applied for element on with jQuery data(key) can be called.
243 *
244 */
245 toHaveData(key : string, expectedValue : string): boolean;
246 toBe(selector: JQuery): boolean;
247
248 /**
249 * Check if DOM element is matched by the given selector.
250 *
251 * @example
252 * // returns true
253 * expect($('<div><span class="some-class"></span></div>')).toContain('some-class')
254 */
255 toContain(selector: JQuery): boolean;
256
257 /**
258 * Check if DOM element exists inside the given parent element.
259 *
260 * @example
261 * // returns true
262 * expect($('<div><span class="some-class"></span></div>')).toContainElement('span.some-class')
263 */
264 toContainElement(selector: string): boolean;
265
266 /**
267 * Check to see if the set of matched elements matches the given selector
268 *
269 * @example
270 * expect($('<span></span>').addClass('js-something')).toBeMatchedBy('.js-something')
271 *
272 * @returns {Boolean} true if DOM contains the element
273 */
274 toBeMatchedBy(selector: string): boolean;
275
276 /**
277 * Only for tags that have disabled attribute
278 * @example
279 * // returns true
280 * expect('<input type="submit" disabled="disabled"/>').toBeDisabled()
281 */
282 toBeDisabled(): boolean;
283
284 /**
285 * Check if DOM element is focused
286 * @example
287 * // returns true
288 * expect($('<input type="text" />').focus()).toBeFocused()
289 */
290 toBeFocused(): boolean;
291
292 /**
293 * Checks if DOM element handles event.
294 *
295 * @example
296 * // returns true
297 * expect($form).toHandle("submit")
298 */
299 toHandle(eventName: string): boolean;
300
301 /**
302 * Assigns a callback to an event of the DOM element.
303 *
304 * @param eventName Name of the event to assign the callback to.
305 * @param eventHandler Callback function to be assigned.
306 *
307 * @example
308 * expect($form).toHandleWith("submit", yourSubmitCallback)
309 */
310 toHandleWith(eventName: string, eventHandler : JQueryCallback): boolean;
311
312 /**
313 * Checks if event was triggered.
314 */
315 toHaveBeenTriggered(): boolean;
316
317 /**
318 * Checks if the event has been triggered on selector.
319 * @param selector Selector that should have triggered the event.
320 */
321 toHaveBeenTriggeredOn(selector: string): boolean;
322
323 /**
324 * Checks if the event has been triggered on selector.
325 * @param selector Selector that should have triggered the event.
326 * @param args Extra arguments to be passed to jQuery events functions.
327 */
328 toHaveBeenTriggeredOnAndWith(selector: string, ...args: any[]): boolean;
329
330 /**
331 * Checks if event propagation has been prevented.
332 */
333 toHaveBeenPrevented(): boolean;
334
335 /**
336 * Checks if event propagation has been prevented on element with selector.
337 *
338 * @param selector Selector that should have prevented the event.
339 */
340 toHaveBeenPreventedOn(selector: string): boolean;
341
342 /**
343 * Checks if event propagation has been stopped.
344 *
345 * @example
346 * // returns true
347 * var spyEvent = spyOnEvent('#some_element', 'click')
348 * $('#some_element').click(function (event){event.stopPropagation();})
349 * $('#some_element').click()
350 * expect(spyEvent).toHaveBeenStopped()
351 */
352 toHaveBeenStopped(): boolean;
353
354 /**
355 * Checks if event propagation has been stopped by an element with the given selector.
356 * @param selector Selector of the element that should have stopped the event propagation.
357 *
358 * @example
359 * // returns true
360 * $('#some_element').click(function (event){event.stopPropagation();})
361 * $('#some_element').click()
362 * expect('click').toHaveBeenStoppedOn('#some_element')
363 */
364 toHaveBeenStoppedOn(selector: string): boolean;
365
366 /**
367 * Checks to see if the matched element is attached to the DOM.
368 * @example
369 * expect($('#id-name')[0]).toBeInDOM()
370 */
371 toBeInDOM(): boolean;
372
373 }
374
375 interface JQueryEventSpy {
376 selector: string;
377 eventName: string;
378 handler(eventObject: JQueryEventObject): any;
379 reset(): any;
380 }
381
382 interface JasmineJQuery {
383 browserTagCaseIndependentHtml(html: string): string;
384 elementToString(element: JQuery): string;
385 matchersClass: any;
386 events: JasmineJQueryEvents;
387 }
388
389 interface JasmineJQueryEvents {
390 spyOn(selector: string, eventName: string): JQueryEventSpy;
391 args(selector: string, eventName: string): any;
392 wasTriggered(selector: string, eventName: string): boolean;
393 wasTriggeredWith(selector: string, eventName: string, expectedArgs: any, env: jasmine.Env): boolean;
394 wasPrevented(selector: string, eventName: string): boolean;
395 wasStopped(selector: string, eventName: string): boolean;
396 cleanUp() : void;
397 }
398
399 var JQuery: JasmineJQuery;
400}