diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2023-12-19 00:33:38 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-19 05:33:38 +0000 |
commit | 1ced9aafc00c10992bab8bd3f1b6b1397f05b7b9 (patch) | |
tree | 305bb2b3bfc7fc3b051ee1cd3d1c35f442af0de4 /test/dom-text-scanner.test.js | |
parent | 5f96276fda93dcad39f2165fd3c8d890aa5f9be5 (diff) |
Make JSON.parse usage safer (#373)
* Make JSON.parse usage safer
* Fix any type
* Add readResponseJson
* Use readResponseJson
* Additional updates
* Rename files
* Add types
Diffstat (limited to 'test/dom-text-scanner.test.js')
-rw-r--r-- | test/dom-text-scanner.test.js | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/test/dom-text-scanner.test.js b/test/dom-text-scanner.test.js index d62e334d..f53e326d 100644 --- a/test/dom-text-scanner.test.js +++ b/test/dom-text-scanner.test.js @@ -19,6 +19,7 @@ import {fileURLToPath} from 'node:url'; import path from 'path'; import {describe, expect} from 'vitest'; +import {parseJson} from '../dev/json.js'; import {DOMTextScanner} from '../ext/js/dom/dom-text-scanner.js'; import {createDomTest} from './fixtures/dom-test.js'; @@ -109,28 +110,33 @@ describe('DOMTextScanner', () => { window.getComputedStyle = createAbsoluteGetComputedStyle(window); for (const testElement of /** @type {NodeListOf<HTMLElement>} */ (document.querySelectorAll('y-test'))) { - let testData = JSON.parse(/** @type {string} */ (testElement.dataset.testData)); + /** @type {import('test/dom-text-scanner').TestData|import('test/dom-text-scanner').TestData[]} */ + let testData = parseJson(/** @type {string} */ (testElement.dataset.testData)); if (!Array.isArray(testData)) { testData = [testData]; } for (const testDataItem of testData) { - let { - node, + const { + node: nodeSelector, offset, length, forcePreserveWhitespace, generateLayoutContent, reversible, expected: { - node: expectedNode, + node: expectedNodeSelector, offset: expectedOffset, content: expectedContent, remainder: expectedRemainder } } = testDataItem; - node = querySelectorTextNode(testElement, node); - expectedNode = querySelectorTextNode(testElement, expectedNode); + const node = querySelectorTextNode(testElement, nodeSelector); + const expectedNode = querySelectorTextNode(testElement, expectedNodeSelector); + + expect(node).not.toEqual(null); + expect(expectedNode).not.toEqual(null); + if (node === null || expectedNode === null) { continue; } // Standard test { |