Skip to content
Closed
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 @@ -718,7 +718,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 @@ -949,7 +949,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
9 changes: 8 additions & 1 deletion test/domino.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,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 @@ -488,7 +495,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
Loading