diff --git a/API.md b/API.md index a937292b7..564eed088 100644 --- a/API.md +++ b/API.md @@ -152,7 +152,7 @@ Assert an [HTMLElement][118] (or multiple) matching the `selector` exists. #### Examples ```javascript -assert.dom('#title').exists(); +assert.dom('#title').exists(); assert.dom('.choice').exists({ count: 4 }); ``` @@ -352,7 +352,7 @@ but not necessarily in the viewport. #### Examples ```javascript -assert.dom('#title').isVisible(); +assert.dom('#title').isVisible(); assert.dom('.choice').isVisible({ count: 4 }); ``` @@ -475,7 +475,7 @@ expression. #### Parameters - `name` **[string][121]** -- `value` **([string][121] \| [RegExp][132])** +- `value` **([RegExp][132] \| any)** - `message` **[string][121]?** #### Examples @@ -592,9 +592,9 @@ Assert that the [HTMLElement][] has the `expected` style declarations using #### Examples ```javascript -assert.dom('.progress-bar').hasStyle({ - opacity: 1, - display: 'block' +assert.dom('.progress-bar').hasStyle({ + opacity: 1, + display: 'block' }); ``` @@ -615,8 +615,8 @@ Assert that the pseudo element for `selector` of the [HTMLElement][] has the `ex #### Examples ```javascript -assert.dom('.progress-bar').hasPseudoElementStyle(':after', { - content: '";"', +assert.dom('.progress-bar').hasPseudoElementStyle(':after', { + content: '";"', }); ``` @@ -636,9 +636,9 @@ Assert that the [HTMLElement][] does not have the `expected` style declarations #### Examples ```javascript -assert.dom('.progress-bar').doesNotHaveStyle({ - opacity: 1, - display: 'block' +assert.dom('.progress-bar').doesNotHaveStyle({ + opacity: 1, + display: 'block' }); ``` @@ -659,8 +659,8 @@ Assert that the pseudo element for `selector` of the [HTMLElement][] does not ha #### Examples ```javascript -assert.dom('.progress-bar').doesNotHavePseudoElementStyle(':after', { - content: '";"', +assert.dom('.progress-bar').doesNotHavePseudoElementStyle(':after', { + content: '";"', }); ``` @@ -690,10 +690,10 @@ attribute and stripping/collapsing whitespace. #### Examples ```javascript -//

-// Welcome to QUnit -//

- +//

+// Welcome to QUnit +//

+ assert.dom('#title').hasText('Welcome to QUnit'); ``` @@ -895,10 +895,10 @@ property of the [HTMLElement][118]. #### Examples ```javascript -//

-// Title -//

- +//

+// Title +//

+ assert.dom('#title').hasTagName('h1'); ``` @@ -918,10 +918,10 @@ property of the [HTMLElement][118]. #### Examples ```javascript -//
-// Title -//
- +//
+// Title +//
+ assert.dom('section#block').doesNotHaveTagName('div'); ``` diff --git a/lib/__tests__/has-property.ts b/lib/__tests__/has-property.ts index cc13d67ea..0d5cba6d9 100644 --- a/lib/__tests__/has-property.ts +++ b/lib/__tests__/has-property.ts @@ -8,45 +8,45 @@ describe('assert.dom(...).hasProperty()', () => { beforeEach(() => { assert = new TestAssertions(); - document.body.innerHTML = ''; + document.body.innerHTML = ''; }); - describe('string expected', () => { + describe('non-regex expected', () => { test('succeeds for correct name and value', () => { - assert.dom('input').hasProperty('type', 'password'); - assert.dom(document.querySelector('input')).hasProperty('type', 'password'); + assert.dom('input').hasProperty('checked', false); + assert.dom(document.querySelector('input')).hasProperty('checked', false); expect(assert.results).toEqual([ { - actual: 'Element input has property "type" with value "password"', - expected: 'Element input has property "type" with value "password"', - message: 'Element input has property "type" with value "password"', + actual: 'Element input has property "checked" with value false', + expected: 'Element input has property "checked" with value false', + message: 'Element input has property "checked" with value false', result: true, }, { - actual: 'Element input[type="password"] has property "type" with value "password"', - expected: 'Element input[type="password"] has property "type" with value "password"', - message: 'Element input[type="password"] has property "type" with value "password"', + actual: 'Element input[type="checkbox"] has property "checked" with value false', + expected: 'Element input[type="checkbox"] has property "checked" with value false', + message: 'Element input[type="checkbox"] has property "checked" with value false', result: true, }, ]); }); test('fails for wrong value', () => { - assert.dom('input').hasProperty('type', 'text'); - assert.dom(document.querySelector('input')).hasProperty('type', 'text'); + assert.dom('input').hasProperty('checked', true); + assert.dom(document.querySelector('input')).hasProperty('checked', true); expect(assert.results).toEqual([ { - actual: 'Element input has property "type" with value "password"', - expected: 'Element input has property "type" with value "text"', - message: 'Element input has property "type" with value "text"', + actual: 'Element input has property "checked" with value false', + expected: 'Element input has property "checked" with value true', + message: 'Element input has property "checked" with value true', result: false, }, { - actual: 'Element input[type="password"] has property "type" with value "password"', - expected: 'Element input[type="password"] has property "type" with value "text"', - message: 'Element input[type="password"] has property "type" with value "text"', + actual: 'Element input[type="checkbox"] has property "checked" with value false', + expected: 'Element input[type="checkbox"] has property "checked" with value true', + message: 'Element input[type="checkbox"] has property "checked" with value true', result: false, }, ]); @@ -55,21 +55,21 @@ describe('assert.dom(...).hasProperty()', () => { describe('regex expected', () => { test('succeeds for matching name and value', () => { - assert.dom('input').hasProperty('type', /^pass/); - assert.dom(document.querySelector('input')).hasProperty('type', /^pass/); + assert.dom('input').hasProperty('type', /^check/); + assert.dom(document.querySelector('input')).hasProperty('type', /^check/); expect(assert.results).toEqual([ { - actual: 'Element input has property "type" with value "password"', - expected: 'Element input has property "type" with value matching /^pass/', - message: 'Element input has property "type" with value matching /^pass/', + actual: 'Element input has property "type" with value "checkbox"', + expected: 'Element input has property "type" with value matching /^check/', + message: 'Element input has property "type" with value matching /^check/', result: true, }, { - actual: 'Element input[type="password"] has property "type" with value "password"', + actual: 'Element input[type="checkbox"] has property "type" with value "checkbox"', expected: - 'Element input[type="password"] has property "type" with value matching /^pass/', - message: 'Element input[type="password"] has property "type" with value matching /^pass/', + 'Element input[type="checkbox"] has property "type" with value matching /^check/', + message: 'Element input[type="checkbox"] has property "type" with value matching /^check/', result: true, }, ]); @@ -81,16 +81,16 @@ describe('assert.dom(...).hasProperty()', () => { expect(assert.results).toEqual([ { - actual: 'Element input has property "type" with value "password"', + actual: 'Element input has property "type" with value "checkbox"', expected: 'Element input has property "type" with value matching /mail$/', message: 'Element input has property "type" with value matching /mail$/', result: false, }, { - actual: 'Element input[type="password"] has property "type" with value "password"', + actual: 'Element input[type="checkbox"] has property "type" with value "checkbox"', expected: - 'Element input[type="password"] has property "type" with value matching /mail$/', - message: 'Element input[type="password"] has property "type" with value matching /mail$/', + 'Element input[type="checkbox"] has property "type" with value matching /mail$/', + message: 'Element input[type="checkbox"] has property "type" with value matching /mail$/', result: false, }, ]); diff --git a/lib/assertions.ts b/lib/assertions.ts index 6c8b8f01a..c72d510a2 100644 --- a/lib/assertions.ts +++ b/lib/assertions.ts @@ -528,7 +528,7 @@ export default class DOMAssertions { * * @see {@link #doesNotHaveProperty} */ - hasProperty(name: string, value: string | RegExp, message?: string): DOMAssertions { + hasProperty(name: string, value: unknown, message?: string): DOMAssertions { let element = this.findTargetElement(); if (!element) return this;