Merge pull request #18158 from devoto13/jasmine_dom_matchers

Added types for jasmine_dom_matchers
This commit is contained in:
Wesley Wigham
2017-07-17 17:28:32 -07:00
committed by GitHub
4 changed files with 184 additions and 0 deletions

135
types/jasmine_dom_matchers/index.d.ts vendored Normal file
View File

@@ -0,0 +1,135 @@
// Type definitions for jasmine_dom_matchers 1.4
// Project: http://github.com/charleshansen/jasmine_dom_matchers
// Definitions by: Yaroslav Admin <https://github.com/devoto13>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="jasmine" />
declare namespace jasmine {
interface Matchers<T> {
/**
* Checks if element has visibility `hidden` or `height` or `width = 0`.
*
* The reverse of {@link toBeVisible}.
*
* @return {boolean}
*/
toBeHidden(): boolean;
/**
* Checks if element has visibility style not `hidden` and both `height` and `width > 0`.
*
* The reverse of {@link toBeHidden}.
*
* @return {boolean}
*/
toBeVisible(): boolean;
/**
* Checks element attributes.
* `attributeValue` is optional, if omitted, will check that the attribute exists.
*
* @param {string} attributeName
* @param {string | number | RegExp} attributeValue
* @return {boolean}
*/
toHaveAttr(attributeName: string, attributeValue?: string | number | RegExp): boolean;
/**
* Checks element properties.
* `propertyValue` is optional, if omitted, will check that the property exists.
*
* @param {string} propertyName
* @param {string | number | RegExp} propertyValue
* @return {boolean}
*/
toHaveProp(propertyName: string, propertyValue?: string | number | RegExp): boolean;
/**
* Checks if all styles are present.
* `styles` is an object, all styles given in that object will be checked.
*
* @param {{[p: string]: string | number | RegExp}} styles
* @return {boolean}
*/
toHaveCss(styles: { [ cssProperty: string]: string | number | RegExp }): boolean;
/**
* Checks the `value` of eligible elements (like inputs).
*
* @param {string | number | RegExp} value
* @return {boolean}
*/
toHaveValue(value: string | number | RegExp): boolean;
/**
* Checks if element has a `checked` property, only useful for checkbox inputs.
*
* @return {boolean}
*/
toBeChecked(): boolean;
/**
* Checks if element is focused.
*
* @return {boolean}
*/
toBeFocused(): boolean;
/**
* Checks if element has a `selected` property, only useful for options.
*
* @return {boolean}
*/
toBeSelected(): boolean;
/**
* Checks if element has a disabled property.
*
* @return {boolean}
*/
toBeDisabled(): boolean;
/**
* Checks for presence of classes on the element.
* If `className` is an Array, checks for all classes in the array.
*
* @param {string | string[]} className
* @return {boolean}
*/
toHaveClass(className: string | string[]): boolean;
/**
* Checks for exact match with text, after trimming whitespace.
*
* @param {string | number | RegExp} text
* @return {boolean}
*/
toHaveText(text: string | number | RegExp): boolean;
/**
* Checks if text substring is contained within element.
*
* @param {string | number | RegExp} text
* @return {boolean}
*/
toContainText(text: string | number | RegExp): boolean;
/**
* Checks for length number of html elements.
* Also works for plain Arrays.
*
* @param {number} length
* @return {boolean}
*/
toHaveLength(length: number): boolean;
/**
* True if the element exists, does not have to be in the DOM.
*
* @return {boolean}
*/
toExist(): boolean;
}
}

View File

@@ -0,0 +1,25 @@
let input: HTMLInputElement = new HTMLInputElement();
let paragraph: HTMLParagraphElement = new HTMLParagraphElement();
let option: HTMLOptionElement = new HTMLOptionElement();
expect(paragraph).toBeHidden();
expect(paragraph).toBeVisible();
expect(paragraph).toHaveAttr('alt');
expect(paragraph).toHaveAttr('alt', 'Some text');
expect(paragraph).toHaveProp('alt');
expect(paragraph).toHaveProp('alt', 'Some text');
expect(paragraph).toHaveCss({ display: 'block' });
expect(paragraph).toHaveCss({ lineHeight: 0 });
expect(paragraph).toHaveCss({ fontSize: /px/ });
expect(input).toHaveValue('42');
expect(input).toBeChecked();
expect(input).toBeFocused();
expect(paragraph).toBeSelected();
expect(input).toBeDisabled();
expect(paragraph).toHaveClass('someClass');
expect(paragraph).toHaveText('Some text');
expect(paragraph).toContainText('text');
expect(paragraph).toContainText(/text/);
expect(paragraph).toContainText(42);
expect(paragraph).toHaveLength(42);
expect(paragraph).toExist();

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"jasmine_dom_matchers-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }