From 9352b8df407b757dc1c18c04e3284a772c956c02 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Tue, 11 Aug 2020 10:51:25 +0300 Subject: [PATCH] Fix typing for `hasProperty` assertion. --- API.md | 2 +- lib/__tests__/has-property.ts | 42 +++++++++++++++++++++++++++++++++++ lib/assertions.ts | 4 ++-- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/API.md b/API.md index a937292b7..6a29b7aeb 100644 --- a/API.md +++ b/API.md @@ -475,7 +475,7 @@ expression. #### Parameters - `name` **[string][121]** -- `value` **([string][121] \| [RegExp][132])** +- `value` **([RegExp][132] | any)** - `message` **[string][121]?** #### Examples diff --git a/lib/__tests__/has-property.ts b/lib/__tests__/has-property.ts index cc13d67ea..a9d75d16e 100644 --- a/lib/__tests__/has-property.ts +++ b/lib/__tests__/has-property.ts @@ -53,6 +53,48 @@ describe('assert.dom(...).hasProperty()', () => { }); }); + describe('boolean expected', () => { + test('succeeds for correct name and value', () => { + assert.dom('input').hasProperty('disabled', false); + assert.dom(document.querySelector('input')).hasProperty('disabled', false); + + expect(assert.results).toEqual([ + { + actual: 'Element input has property "disabled" with value false', + expected: 'Element input has property "disabled" with value false', + message: 'Element input has property "disabled" with value false', + result: true, + }, + { + actual: 'Element input[type="password"] has property "disabled" with value false', + expected: 'Element input[type="password"] has property "disabled" with value false', + message: 'Element input[type="password"] has property "disabled" with value false', + result: true, + }, + ]); + }); + + test('fails for wrong value', () => { + assert.dom('input').hasProperty('disabled', true); + assert.dom(document.querySelector('input')).hasProperty('disabled', true); + + expect(assert.results).toEqual([ + { + actual: 'Element input has property "disabled" with value false', + expected: 'Element input has property "disabled" with value true', + message: 'Element input has property "disabled" with value true', + result: false, + }, + { + actual: 'Element input[type="password"] has property "disabled" with value false', + expected: 'Element input[type="password"] has property "disabled" with value true', + message: 'Element input[type="password"] has property "disabled" with value true', + result: false, + }, + ]); + }); + }); + describe('regex expected', () => { test('succeeds for matching name and value', () => { assert.dom('input').hasProperty('type', /^pass/); diff --git a/lib/assertions.ts b/lib/assertions.ts index 6c8b8f01a..416de3286 100644 --- a/lib/assertions.ts +++ b/lib/assertions.ts @@ -520,7 +520,7 @@ export default class DOMAssertions { * expression. * * @param {string} name - * @param {string|RegExp} value + * @param {RegExp|any} value * @param {string?} message * * @example @@ -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;