Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 9 additions & 2 deletions test/domino.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -838,7 +845,7 @@ exports.eqAttr = function() {
var html = "<div id=a ==x><a=B></A=b></div>";
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);
Expand Down Expand Up @@ -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);
Expand Down
Loading