Skip to content

Commit

Permalink
Fix nwsapi to v2.2.2 (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
asamuzaK authored Feb 17, 2024
1 parent e989743 commit 3717e4e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 10 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"bidi-js": "^1.0.3",
"css-tree": "^2.3.1",
"is-potential-custom-element-name": "^1.0.1",
"nwsapi": "^2.2.7"
"nwsapi": "2.2.2"
},
"devDependencies": {
"@types/css-tree": "^2.3.6",
Expand All @@ -42,13 +42,16 @@
"eslint-plugin-regexp": "^2.2.0",
"eslint-plugin-unicorn": "^51.0.1",
"happy-dom": "^13.3.8",
"jsdom": "24.0.0",
"jsdom": "^24.0.0",
"linkedom": "^0.16.8",
"mocha": "^10.3.0",
"sinon": "^17.0.1",
"typescript": "^5.3.3",
"wpt-runner": "^5.0.0"
},
"overrides": {
"nwsapi": "2.2.2"
},
"scripts": {
"bench": "node benchmark/bench.js",
"bench-sizzle": "node benchmark/bench-sizzle.js",
Expand Down
71 changes: 63 additions & 8 deletions test/jsdom-issues.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,69 +21,77 @@ const jsdom = (str = '') => {
url: 'http://localhost/',
beforeParse: window => {
const domSelector = new DOMSelector(window);

const matches = domSelector.matches.bind(domSelector);
window.Element.prototype.matches = function (...args) {
if (!args.length) {
const msg = '1 argument required, but only 0 present.';
throw new window.TypeError(msg);
}
const [selector] = args;
return domSelector.matches(selector, this);
return matches(selector, this);
};

const closest = domSelector.closest.bind(domSelector);
window.Element.prototype.closest = function (...args) {
if (!args.length) {
const msg = '1 argument required, but only 0 present.';
throw new window.TypeError(msg);
}
const [selector] = args;
return domSelector.closest(selector, this);
return closest(selector, this);
};

const querySelector = domSelector.querySelector.bind(domSelector);
window.Document.prototype.querySelector = function (...args) {
if (!args.length) {
const msg = '1 argument required, but only 0 present.';
throw new window.TypeError(msg);
}
const [selector] = args;
return domSelector.querySelector(selector, this);
return querySelector(selector, this);
};
window.DocumentFragment.prototype.querySelector = function (...args) {
if (!args.length) {
const msg = '1 argument required, but only 0 present.';
throw new window.TypeError(msg);
}
const [selector] = args;
return domSelector.querySelector(selector, this);
return querySelector(selector, this);
};
window.Element.prototype.querySelector = function (...args) {
if (!args.length) {
const msg = '1 argument required, but only 0 present.';
throw new window.TypeError(msg);
}
const [selector] = args;
return domSelector.querySelector(selector, this);
return querySelector(selector, this);
};

const querySelectorAll = domSelector.querySelectorAll.bind(domSelector);
window.Document.prototype.querySelectorAll = function (...args) {
if (!args.length) {
const msg = '1 argument required, but only 0 present.';
throw new window.TypeError(msg);
}
const [selector] = args;
return domSelector.querySelectorAll(selector, this);
return querySelectorAll(selector, this);
};
window.DocumentFragment.prototype.querySelectorAll = function (...args) {
if (!args.length) {
const msg = '1 argument required, but only 0 present.';
throw new window.TypeError(msg);
}
const [selector] = args;
return domSelector.querySelectorAll(selector, this);
return querySelectorAll(selector, this);
};
window.Element.prototype.querySelectorAll = function (...args) {
if (!args.length) {
const msg = '1 argument required, but only 0 present.';
throw new window.TypeError(msg);
}
const [selector] = args;
return domSelector.querySelectorAll(selector, this);
return querySelectorAll(selector, this);
};
}
});
Expand Down Expand Up @@ -492,6 +500,53 @@ describe('jsdom issues tagged with `selectors` label', () => {
});
});

describe('#3544 - https://github.com/jsdom/jsdom/issues/3544', () => {
let document;
beforeEach(() => {
const dom = jsdom();
document = dom.window.document;
});
afterEach(() => {
document = null;
});

it('should get matched node(s)', () => {
const body = document.body;
const div = document.createElement('div');
const ul = document.createElement('ul');
const li = document.createElement('li');
ul.appendChild(li);
div.appendChild(ul);
body.appendChild(div);
const res1 = div.querySelectorAll('UL');
const res2 = div.querySelectorAll('ul');
const res3 = div.querySelectorAll('ul > li');
const res4 = div.querySelectorAll('UL > LI');
assert.deepEqual(res1, [ul], 'result1');
assert.deepEqual(res2, [ul], 'result2');
assert.deepEqual(res3, [li], 'result3');
assert.deepEqual(res4, [li], 'result4');
});

it('should get matched node(s)', () => {
const body = document.body;
const div = document.createElement('div');
const ul = document.createElement('ul');
const li = document.createElement('li');
ul.appendChild(li);
div.appendChild(ul);
body.appendChild(div);
const res1 = ul.matches('UL');
const res2 = ul.matches('ul');
const res3 = li.matches('ul > li');
const res4 = li.matches('UL > LI');
assert.isTrue(res1, 'result1');
assert.isTrue(res2, 'result2');
assert.isTrue(res3, 'result3');
assert.isTrue(res4, 'result4');
});
});

describe('#3666 - https://github.com/jsdom/jsdom/issues/3666', () => {
const html = `
<!doctype html>
Expand Down

0 comments on commit 3717e4e

Please sign in to comment.