From 44d2a8c028233808daa318ce2404f69f7b0fc773 Mon Sep 17 00:00:00 2001 From: Yaroslav Admin Date: Tue, 18 Jul 2017 00:33:24 +0200 Subject: [PATCH] Added types for jasmine_dom_matchers --- types/jasmine_dom_matchers/index.d.ts | 135 ++++++++++++++++++ .../jasmine_dom_matchers-tests.ts | 25 ++++ types/jasmine_dom_matchers/tsconfig.json | 23 +++ types/jasmine_dom_matchers/tslint.json | 1 + 4 files changed, 184 insertions(+) create mode 100644 types/jasmine_dom_matchers/index.d.ts create mode 100644 types/jasmine_dom_matchers/jasmine_dom_matchers-tests.ts create mode 100644 types/jasmine_dom_matchers/tsconfig.json create mode 100644 types/jasmine_dom_matchers/tslint.json diff --git a/types/jasmine_dom_matchers/index.d.ts b/types/jasmine_dom_matchers/index.d.ts new file mode 100644 index 0000000000..f463a5ebce --- /dev/null +++ b/types/jasmine_dom_matchers/index.d.ts @@ -0,0 +1,135 @@ +// Type definitions for jasmine_dom_matchers 1.4 +// Project: http://github.com/charleshansen/jasmine_dom_matchers +// Definitions by: Yaroslav Admin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +/// + +declare namespace jasmine { + interface Matchers { + /** + * 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; + } +} diff --git a/types/jasmine_dom_matchers/jasmine_dom_matchers-tests.ts b/types/jasmine_dom_matchers/jasmine_dom_matchers-tests.ts new file mode 100644 index 0000000000..3edd13ec89 --- /dev/null +++ b/types/jasmine_dom_matchers/jasmine_dom_matchers-tests.ts @@ -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(); diff --git a/types/jasmine_dom_matchers/tsconfig.json b/types/jasmine_dom_matchers/tsconfig.json new file mode 100644 index 0000000000..30a9ab129d --- /dev/null +++ b/types/jasmine_dom_matchers/tsconfig.json @@ -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" + ] +} diff --git a/types/jasmine_dom_matchers/tslint.json b/types/jasmine_dom_matchers/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/jasmine_dom_matchers/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }