Skip to content

Commit

Permalink
Fix typing for hasProperty assertion.
Browse files Browse the repository at this point in the history
  • Loading branch information
wuron committed Aug 11, 2020
1 parent 6d87808 commit 9352b8d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ expression.
#### Parameters

- `name` **[string][121]**
- `value` **([string][121] \| [RegExp][132])**
- `value` **([RegExp][132] | any)**
- `message` **[string][121]?**

#### Examples
Expand Down
42 changes: 42 additions & 0 deletions lib/__tests__/has-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
Expand Down
4 changes: 2 additions & 2 deletions lib/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,15 +520,15 @@ export default class DOMAssertions {
* expression.
*
* @param {string} name
* @param {string|RegExp} value
* @param {RegExp|any} value
* @param {string?} message
*
* @example
* assert.dom('input.password-input').hasProperty('type', 'password');
*
* @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;

Expand Down

0 comments on commit 9352b8d

Please sign in to comment.