Skip to content

Commit

Permalink
Adding tests to covert exists when passing null for Element
Browse files Browse the repository at this point in the history
  • Loading branch information
scalvert authored and Turbo87 committed Feb 2, 2020
1 parent f1ee1a1 commit c89efea
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
15 changes: 15 additions & 0 deletions lib/__tests__/exists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ describe('assert.dom(...).exists()', () => {
},
]);
});

test('fails if element is missing', () => {
document.body.innerHTML = '<h1 class="baz">foo</h1>bar';

assert.dom(null).isVisible();

expect(assert.results).toEqual([
{
actual: 'Element <not found> is not visible',
expected: 'Element <not found> is visible',
message: 'Element <not found> is visible',
result: false,
},
]);
});
});

describe('custom messages', () => {
Expand Down
19 changes: 16 additions & 3 deletions lib/__tests__/is-visible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ describe('assert.dom(...).isVisible()', () => {
},
]);
});

test('fails if element is missing', () => {
document.body.innerHTML = '<h1 class="baz">foo</h1>bar';

assert.dom('h2').isVisible();

expect(assert.results).toEqual([
{
actual: 'Element h2 is not visible',
expected: 'Element h2 is visible',
message: 'Element h2 is visible',
result: false,
},
]);
});
});

describe('custom messages', () => {
Expand All @@ -55,9 +70,7 @@ describe('assert.dom(...).isVisible()', () => {
test('fails for missing element', () => {
document.body.innerHTML = '<h1 class="baz">foo</h1>bar';

const headingElement = document.querySelector('h2');
console.log(headingElement);
assert.dom(headingElement).isVisible();
assert.dom(null).isVisible();

expect(assert.results).toEqual([
{
Expand Down
3 changes: 0 additions & 3 deletions tests/acceptance/qunit-dom-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ module('Acceptance | qunit-dom', function(hooks) {
assert.dom('#hidden-input').isNotVisible();
assert.dom('p').isVisible({ count: 2 });

let titleElement = document.querySelector('#title');
assert.dom(titleElement).isVisible();

/*
* JSDom does not implement pseudo elements and this can only be tested in a real browser.
* See this: https://github.com/jsdom/jsdom/issues/1928
Expand Down

0 comments on commit c89efea

Please sign in to comment.