Skip to content

Commit

Permalink
fix: querySelector returns null when nothing is found.
Browse files Browse the repository at this point in the history
Also: commenting unused tests code that prevented running the unit tests.

Fixes angular/angular#51068
  • Loading branch information
JeanMeche committed Mar 28, 2024
1 parent aa8de34 commit e2a1969
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
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

0 comments on commit e2a1969

Please sign in to comment.