Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Koooooo-7 authored Apr 22, 2023
2 parents c9c7188 + f4f21a3 commit 5f9139f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/core/event/scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ export function scrollIntoView(path, id) {
return;
}
const topMargin = config().topMargin;
const section = dom.find('#' + id);
// Use [id='1234'] instead of #id to handle special cases such as reserved characters and pure number id
// https://stackoverflow.com/questions/37270787/uncaught-syntaxerror-failed-to-execute-queryselector-on-document
const section = dom.find("[id='" + id + "']");
section && scrollTo(section, topMargin);

const li = nav[getNavKey(path, id)];
Expand Down
25 changes: 20 additions & 5 deletions test/unit/example.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import * as getTimeOfDayModule from './fixtures/get-time-of-day.js';

// Suite
// -----------------------------------------------------------------------------
describe(`Example Tests`, function() {
describe(`Example Tests`, function () {
// Tests
// ---------------------------------------------------------------------------
describe('Jest & JSDOM basics', function() {
describe('Jest & JSDOM basics', function () {
test('dom manipulation (jsdom)', () => {
const testText = 'This is a test';
const testHTML = `<h1>Test</h1><p>${testText}</p>`;
Expand Down Expand Up @@ -53,7 +53,7 @@ describe(`Example Tests`, function() {
});
});

describe('Fake Timers', function() {
describe('Fake Timers', function () {
// jest version issue
// test('data & time', () => {
// jest.useFakeTimers();
Expand All @@ -63,7 +63,7 @@ describe(`Example Tests`, function() {
// });
});

describe('Mocks & Spies', function() {
describe('Mocks & Spies', function () {
test('mock import/require dependency using jest.fn()', () => {
const testModule = require('./fixtures/get-time-of-day.js');
const { greet: testGreet } = require('./fixtures/greet.js');
Expand All @@ -82,7 +82,7 @@ describe(`Example Tests`, function() {

jest.doMock(mockModulePath, () => ({
__esModule: true,
getTimeOfDay: jest.fn(() => 'night')
getTimeOfDay: jest.fn(() => 'night'),
}));

const mockGetTimeOfDay = require(mockModulePath).getTimeOfDay;
Expand Down Expand Up @@ -116,4 +116,19 @@ describe(`Example Tests`, function() {
expect(greeting).toBe(`Good night, John!`);
});
});

describe('Verify Special Changes Test Case', function () {
test('document.querySelector with id=pure number', () => {
const testText = 'This is a test';
const testHTML = `<div id=24><p>${testText}</p></div>`;

// Inject HTML
document.body.innerHTML = testHTML;
expect(() => {
document.querySelector('#24');
}).toThrow(DOMException);

expect(document.querySelector("[id='24']").textContent).toBe(testText);
});
});
});

0 comments on commit 5f9139f

Please sign in to comment.