diff --git a/packages/qunit-dom/lib/__tests__/does-not-exist.ts b/packages/qunit-dom/lib/__tests__/does-not-exist.ts index 59fdedb97..378200814 100644 --- a/packages/qunit-dom/lib/__tests__/does-not-exist.ts +++ b/packages/qunit-dom/lib/__tests__/does-not-exist.ts @@ -54,6 +54,21 @@ describe('assert.dom(...).doesNotExist()', () => { }, ]); }); + + test('fails if passed null', () => { + document.body.innerHTML = '

foo

bar'; + + assert.dom(null).doesNotExist(); + + expect(assert.results).toEqual([ + { + actual: 'Element does not exist', + expected: 'Element does not exist', + message: 'Element does not exist', + result: true, + }, + ]); + }); }); test('custom message', () => { diff --git a/packages/qunit-dom/lib/__tests__/does-not-have-attribute.ts b/packages/qunit-dom/lib/__tests__/does-not-have-attribute.ts index 40a1beff5..55ac346c2 100644 --- a/packages/qunit-dom/lib/__tests__/does-not-have-attribute.ts +++ b/packages/qunit-dom/lib/__tests__/does-not-have-attribute.ts @@ -83,6 +83,17 @@ describe('assert.dom(...).doesNotHaveAttribute()', () => { ]); }); + test('fails for null', () => { + assert.dom(null).doesNotHaveAttribute('disabled'); + + expect(assert.results).toEqual([ + { + message: 'Element should exist', + result: false, + }, + ]); + }); + test('throws for unexpected parameter types', () => { //@ts-ignore -- These assertions are for JavaScript users who don't have type checking expect(() => assert.dom(5).doesNotHaveAttribute('disabled')).toThrow('Unexpected Parameter: 5'); diff --git a/packages/qunit-dom/lib/__tests__/does-not-have-class.ts b/packages/qunit-dom/lib/__tests__/does-not-have-class.ts index acaa0f6fb..028837cea 100644 --- a/packages/qunit-dom/lib/__tests__/does-not-have-class.ts +++ b/packages/qunit-dom/lib/__tests__/does-not-have-class.ts @@ -117,6 +117,17 @@ describe('assert.dom(...).doesNotHaveClass()', () => { ]); }); + test('fails for null', () => { + assert.dom(null).doesNotHaveClass('foo'); + + expect(assert.results).toEqual([ + { + message: 'Element should exist', + result: false, + }, + ]); + }); + test('throws for unexpected parameter types', () => { //@ts-ignore -- These assertions are for JavaScript users who don't have type checking expect(() => assert.dom(5).doesNotHaveClass('foo')).toThrow('Unexpected Parameter: 5'); diff --git a/packages/qunit-dom/lib/__tests__/does-not-have-style.ts b/packages/qunit-dom/lib/__tests__/does-not-have-style.ts index 755dda489..fab9f06b3 100644 --- a/packages/qunit-dom/lib/__tests__/does-not-have-style.ts +++ b/packages/qunit-dom/lib/__tests__/does-not-have-style.ts @@ -90,6 +90,18 @@ describe('assert.dom(...).doesNotHaveStyle()', () => { ]); }); + test('fails for null', () => { + assert.dom(null).doesNotHaveStyle({ + opacity: 0, + }); + expect(assert.results).toEqual([ + { + message: 'Element should exist', + result: false, + }, + ]); + }); + test('throws for unexpected parameter types', () => { //@ts-ignore -- These assertions are for JavaScript users who don't have type checking expect(() => assert.dom(5).doesNotHaveStyle({ opacity: 1 })).toThrow('Unexpected Parameter: 5'); diff --git a/packages/qunit-dom/lib/__tests__/does-not-match-selector.ts b/packages/qunit-dom/lib/__tests__/does-not-match-selector.ts index d07ae80be..2b753604b 100644 --- a/packages/qunit-dom/lib/__tests__/does-not-match-selector.ts +++ b/packages/qunit-dom/lib/__tests__/does-not-match-selector.ts @@ -82,6 +82,21 @@ describe('assert.dom(...).doesNotMatchSelector()', () => { ]); }); + test('null passed', () => { + assert.dom(null).doesNotMatchSelector('div>p:last-child'); + + expect(assert.results).toEqual([ + { + actual: '0 elements, selected by null, did not also match the selector div>p:last-child.', + expected: + '0 elements, selected by null, did not also match the selector div>p:last-child.', + message: + '0 elements, selected by null, did not also match the selector div>p:last-child.', + result: true, + }, + ]); + }); + test('multiple elements, some matching compareSelector', () => { assert.dom('p').doesNotMatchSelector('div>p'); diff --git a/packages/qunit-dom/lib/__tests__/has-any-text.ts b/packages/qunit-dom/lib/__tests__/has-any-text.ts index c491db025..602e802fe 100644 --- a/packages/qunit-dom/lib/__tests__/has-any-text.ts +++ b/packages/qunit-dom/lib/__tests__/has-any-text.ts @@ -64,6 +64,17 @@ describe('assert.dom(...).hasAnyText()', () => { ]); }); + test('fails for null', () => { + assert.dom(null).hasAnyText(); + + expect(assert.results).toEqual([ + { + message: 'Element should exist', + result: false, + }, + ]); + }); + test('throws for unexpected parameter types', () => { //@ts-ignore -- These assertions are for JavaScript users who don't have type checking expect(() => assert.dom(5).hasAnyText()).toThrow('Unexpected Parameter: 5'); diff --git a/packages/qunit-dom/lib/__tests__/has-any-value.ts b/packages/qunit-dom/lib/__tests__/has-any-value.ts index fa130c4ba..d9d84653c 100644 --- a/packages/qunit-dom/lib/__tests__/has-any-value.ts +++ b/packages/qunit-dom/lib/__tests__/has-any-value.ts @@ -65,6 +65,17 @@ describe('assert.dom(...).hasAnyValue()', () => { ]); }); + test('fails for null', () => { + assert.dom(null).hasAnyValue(); + + expect(assert.results).toEqual([ + { + message: 'Element should exist', + result: false, + }, + ]); + }); + test('throws for unexpected parameter types', () => { //@ts-ignore -- These assertions are for JavaScript users who don't have type checking expect(() => assert.dom(5).hasAnyValue()).toThrow('Unexpected Parameter: 5'); diff --git a/packages/qunit-dom/lib/__tests__/has-attribute.ts b/packages/qunit-dom/lib/__tests__/has-attribute.ts index ca3cfd942..1b2eb9cd1 100644 --- a/packages/qunit-dom/lib/__tests__/has-attribute.ts +++ b/packages/qunit-dom/lib/__tests__/has-attribute.ts @@ -238,6 +238,17 @@ describe('assert.dom(...).hasAttribute()', () => { ]); }); + test('fails for null', () => { + assert.dom(null).hasAttribute('foo'); + + expect(assert.results).toEqual([ + { + message: 'Element should exist', + result: false, + }, + ]); + }); + test('throws for unexpected parameter types', () => { //@ts-ignore -- These assertions are for JavaScript users who don't have type checking expect(() => assert.dom(5).hasAttribute('foo')).toThrow('Unexpected Parameter: 5'); diff --git a/packages/qunit-dom/lib/__tests__/has-class.ts b/packages/qunit-dom/lib/__tests__/has-class.ts index ac9ab744c..95db00759 100644 --- a/packages/qunit-dom/lib/__tests__/has-class.ts +++ b/packages/qunit-dom/lib/__tests__/has-class.ts @@ -112,6 +112,17 @@ describe('assert.dom(...).hasClass()', () => { ]); }); + test('fails for null', () => { + assert.dom(null).hasClass('foo'); + + expect(assert.results).toEqual([ + { + message: 'Element should exist', + result: false, + }, + ]); + }); + test('throws for unexpected parameter types', () => { //@ts-ignore -- These assertions are for JavaScript users who don't have type checking expect(() => assert.dom(5).hasClass('foo')).toThrow('Unexpected Parameter: 5'); diff --git a/packages/qunit-dom/lib/__tests__/has-no-text.ts b/packages/qunit-dom/lib/__tests__/has-no-text.ts index 48e97383c..fe6f4e3ce 100644 --- a/packages/qunit-dom/lib/__tests__/has-no-text.ts +++ b/packages/qunit-dom/lib/__tests__/has-no-text.ts @@ -62,6 +62,17 @@ describe('assert.dom(...).hasNoText()', () => { ]); }); + test('fails for null', () => { + assert.dom(null).hasNoText(); + + expect(assert.results).toEqual([ + { + message: 'Element should exist', + result: false, + }, + ]); + }); + test('throws for unexpected parameter types', () => { //@ts-ignore -- These assertions are for JavaScript users who don't have type checking expect(() => assert.dom(5).hasNoText()).toThrow('Unexpected Parameter: 5'); diff --git a/packages/qunit-dom/lib/__tests__/has-no-value.ts b/packages/qunit-dom/lib/__tests__/has-no-value.ts index 63de2fc45..cb3653e57 100644 --- a/packages/qunit-dom/lib/__tests__/has-no-value.ts +++ b/packages/qunit-dom/lib/__tests__/has-no-value.ts @@ -64,6 +64,17 @@ describe('assert.dom(...).hasNoValue()', () => { ]); }); + test('fails for null', () => { + assert.dom(null).hasNoValue(); + + expect(assert.results).toEqual([ + { + message: 'Element should exist', + result: false, + }, + ]); + }); + test('throws for unexpected parameter types', () => { //@ts-ignore -- These assertions are for JavaScript users who don't have type checking expect(() => assert.dom(5).hasNoValue()).toThrow('Unexpected Parameter: 5'); diff --git a/packages/qunit-dom/lib/__tests__/has-property.ts b/packages/qunit-dom/lib/__tests__/has-property.ts index bce3a2d6b..101ea21c0 100644 --- a/packages/qunit-dom/lib/__tests__/has-property.ts +++ b/packages/qunit-dom/lib/__tests__/has-property.ts @@ -150,6 +150,17 @@ describe('assert.dom(...).hasProperty()', () => { ]); }); + test('fails for null', () => { + assert.dom(null).hasProperty('foo', 'bar'); + + expect(assert.results).toEqual([ + { + message: 'Element should exist', + result: false, + }, + ]); + }); + test('throws for unexpected parameter types', () => { //@ts-ignore -- These assertions are for JavaScript users who don't have type checking expect(() => assert.dom(5).hasProperty('foo', 'bar')).toThrow('Unexpected Parameter: 5'); diff --git a/packages/qunit-dom/lib/__tests__/has-style.ts b/packages/qunit-dom/lib/__tests__/has-style.ts index d6f3af590..d6676c68c 100644 --- a/packages/qunit-dom/lib/__tests__/has-style.ts +++ b/packages/qunit-dom/lib/__tests__/has-style.ts @@ -108,6 +108,18 @@ describe('assert.dom(...).hasStyle()', () => { ]); }); + test('fails for null', () => { + assert.dom(null).hasStyle({ + opacity: 0, + }); + expect(assert.results).toEqual([ + { + message: 'Element should exist', + result: false, + }, + ]); + }); + test('throws for unexpected parameter types', () => { //@ts-ignore -- These assertions are for JavaScript users who don't have type checking expect(() => assert.dom(5).hasStyle({ opacity: 1 })).toThrow('Unexpected Parameter: 5'); diff --git a/packages/qunit-dom/lib/__tests__/has-value.ts b/packages/qunit-dom/lib/__tests__/has-value.ts index 538405fda..2201d8448 100644 --- a/packages/qunit-dom/lib/__tests__/has-value.ts +++ b/packages/qunit-dom/lib/__tests__/has-value.ts @@ -221,6 +221,17 @@ describe('assert.dom(...).hasValue()', () => { ]); }); + test('fails for null', () => { + assert.dom(null).hasValue('foo'); + + expect(assert.results).toEqual([ + { + message: 'Element should exist', + result: false, + }, + ]); + }); + test('throws for unexpected parameter types', () => { //@ts-ignore -- These assertions are for JavaScript users who don't have type checking expect(() => assert.dom(5).hasValue('foo')).toThrow('Unexpected Parameter: 5'); diff --git a/packages/qunit-dom/lib/__tests__/is-not-visible.ts b/packages/qunit-dom/lib/__tests__/is-not-visible.ts index c9e6531cf..4276c2dc8 100644 --- a/packages/qunit-dom/lib/__tests__/is-not-visible.ts +++ b/packages/qunit-dom/lib/__tests__/is-not-visible.ts @@ -34,6 +34,23 @@ describe('assert.dom(...).isNotVisible()', () => { }); }); + describe('element only', () => { + test('succeeds if element is missing', () => { + document.body.innerHTML = '

foo

bar'; + + assert.dom(null).isNotVisible(); + + expect(assert.results).toEqual([ + { + actual: 'Element is not visible', + expected: 'Element is not visible', + message: 'Element is not visible', + result: true, + }, + ]); + }); + }); + describe('custom messages', () => { test('shows custom messages', () => { document.body.innerHTML = '

foo

bar'; diff --git a/packages/qunit-dom/lib/__tests__/matches-selector.ts b/packages/qunit-dom/lib/__tests__/matches-selector.ts index 3be42b8ee..6075615dd 100644 --- a/packages/qunit-dom/lib/__tests__/matches-selector.ts +++ b/packages/qunit-dom/lib/__tests__/matches-selector.ts @@ -82,6 +82,19 @@ describe('assert.dom(...).matchesSelector()', () => { ]); }); + test('null passed', () => { + assert.dom(null).matchesSelector('div>p:last-child'); + + expect(assert.results).toEqual([ + { + actual: '0 elements, selected by null, also match the selector div>p:last-child.', + expected: '0 elements, selected by null, also match the selector div>p:last-child.', + message: '0 elements, selected by null, also match the selector div>p:last-child.', + result: true, + }, + ]); + }); + test('multiple elements not all matching compareSelector', () => { assert.dom('p').matchesSelector('p + p');