Skip to content

Commit e2a1969

Browse files
committed
fix: querySelector returns null when nothing is found.
Also: commenting unused tests code that prevented running the unit tests. Fixes angular/angular#51068
1 parent aa8de34 commit e2a1969

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

lib/Document.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ Document.prototype = Object.create(ContainerNode.prototype, {
718718
}},
719719

720720
querySelector: { value: function(selector) {
721-
return select(selector, this)[0];
721+
return select(selector, this)[0] ?? null;
722722
}},
723723

724724
querySelectorAll: { value: function(selector) {

lib/Element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ Element.prototype = Object.create(ContainerNode.prototype, {
949949
}},
950950

951951
querySelector: { value: function(selector) {
952-
return select(selector, this)[0];
952+
return select(selector, this)[0] ?? null;
953953
}},
954954

955955
querySelectorAll: { value: function(selector) {

test/domino.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ exports.closest = function() {
6060
(r8 === null).should.be.true();
6161
};
6262

63+
exports.querySelector = function() {
64+
var window = createWindow(html);
65+
var d = window.document;
66+
var nothing = d.querySelector('.foobar');
67+
(nothing === null).should.be.true();
68+
};
69+
6370
exports.querySelectorAll = function() {
6471
var window = createWindow(html);
6572
var d = window.document;
@@ -488,7 +495,7 @@ exports.eqAttr = function() {
488495
var html = "<div id=a ==x><a=B></A=b></div>";
489496
var doc = domino.createDocument(html);
490497
var div = doc.querySelector('#a');
491-
(div != null).should.be.true(); // jshint ignore:line
498+
(div !== null).should.be.true(); // jshint ignore:line
492499
div.attributes.length.should.equal(2);
493500
div.attributes.item(1).name.should.equal('=');
494501
div.children.length.should.equal(1);

0 commit comments

Comments
 (0)