diff --git a/lib/Document.js b/lib/Document.js index 4020f745..a1b0fccb 100644 --- a/lib/Document.js +++ b/lib/Document.js @@ -757,7 +757,7 @@ Document.prototype = Object.create(ContainerNode.prototype, { }}, querySelector: { value: function(selector) { - return select(selector, this)[0]; + return select(selector, this)[0] ?? null; }}, querySelectorAll: { value: function(selector) { diff --git a/lib/Element.js b/lib/Element.js index 097ba75e..3fb87c88 100644 --- a/lib/Element.js +++ b/lib/Element.js @@ -955,7 +955,7 @@ Element.prototype = Object.create(ContainerNode.prototype, { }}, querySelector: { value: function(selector) { - return select(selector, this)[0]; + return select(selector, this)[0] ?? null; }}, querySelectorAll: { value: function(selector) { diff --git a/test/domino.js b/test/domino.js index a49ab1fe..2d0bbdcf 100644 --- a/test/domino.js +++ b/test/domino.js @@ -61,6 +61,13 @@ exports.closest = function() { (r8 === null).should.be.true(); }; +exports.querySelector = function() { + var window = createWindow(html); + var d = window.document; + var nothing = d.querySelector('.foobar'); + (nothing === null).should.be.true(); +}; + exports.querySelectorAll = function() { var window = createWindow(html); var d = window.document; @@ -838,7 +845,7 @@ exports.eqAttr = function() { var html = "
"; var doc = domino.createDocument(html); var div = doc.querySelector('#a'); - (div != null).should.be.true(); // jshint ignore:line + (div !== null).should.be.true(); // jshint ignore:line div.attributes.length.should.equal(2); div.attributes.item(1).name.should.equal('='); div.children.length.should.equal(1); @@ -1681,7 +1688,7 @@ exports.emptyAttributeTokenSelectors = { var queryContext = root.nodeName + ': ' + context; assert.strictEqual(root.querySelectorAll(selector).length, 0, queryContext); // Preserve Domino's existing no-match return value. - assert.strictEqual(root.querySelector(selector), undefined, queryContext); + assert.strictEqual(root.querySelector(selector), null, queryContext); }); assert.strictEqual(meta.matches(selector), false, context); assert.strictEqual(meta.closest(selector), null, context);