diff --git a/src/core/event/scroll.js b/src/core/event/scroll.js index bd6661918..d46447b7f 100644 --- a/src/core/event/scroll.js +++ b/src/core/event/scroll.js @@ -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)]; diff --git a/test/unit/example.test.js b/test/unit/example.test.js index d750ae36d..584c55fb7 100644 --- a/test/unit/example.test.js +++ b/test/unit/example.test.js @@ -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 = `
${testText}
`; @@ -53,7 +53,7 @@ describe(`Example Tests`, function() { }); }); - describe('Fake Timers', function() { + describe('Fake Timers', function () { // jest version issue // test('data & time', () => { // jest.useFakeTimers(); @@ -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'); @@ -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; @@ -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 = `${testText}