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 9, 2020
1 parent 6d87808 commit 6fc2987
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 56 deletions.
50 changes: 25 additions & 25 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
```

Expand Down Expand Up @@ -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 });
```

Expand Down 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 Expand Up @@ -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'
});
```

Expand All @@ -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: '";"',
});
```

Expand All @@ -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'
});
```

Expand All @@ -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: '";"',
});
```

Expand Down Expand Up @@ -690,10 +690,10 @@ attribute and stripping/collapsing whitespace.
#### Examples

```javascript
// <h2 id="title">
// Welcome to <b>QUnit</b>
// </h2>

// <h2 id="title">
// Welcome to <b>QUnit</b>
// </h2>

assert.dom('#title').hasText('Welcome to QUnit');
```

Expand Down Expand Up @@ -895,10 +895,10 @@ property of the [HTMLElement][118].
#### Examples

```javascript
// <h1 id="title">
// Title
// </h1>

// <h1 id="title">
// Title
// </h1>

assert.dom('#title').hasTagName('h1');
```

Expand All @@ -918,10 +918,10 @@ property of the [HTMLElement][118].
#### Examples

```javascript
// <section id="block">
// Title
// </section>

// <section id="block">
// Title
// </section>

assert.dom('section#block').doesNotHaveTagName('div');
```

Expand Down
60 changes: 30 additions & 30 deletions lib/__tests__/has-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,45 @@ describe('assert.dom(...).hasProperty()', () => {
beforeEach(() => {
assert = new TestAssertions();

document.body.innerHTML = '<input type="password">';
document.body.innerHTML = '<input type="checkbox">';
});

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,
},
]);
Expand All @@ -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,
},
]);
Expand All @@ -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,
},
]);
Expand Down
2 changes: 1 addition & 1 deletion lib/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 6fc2987

Please sign in to comment.