From 7a8493242c0d08ed251426b376b89779da728e33 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Tue, 2 May 2023 17:30:10 +0200 Subject: [PATCH 1/9] add `get-text-value` helper --- jest/create-jest-config.cjs | 6 +- jest/polyfills.ts | 15 ++++ .../src/utils/get-text-value.test.ts | 69 +++++++++++++++++++ .../src/utils/get-text-value.ts | 68 ++++++++++++++++++ .../src/utils/get-text-value.test.ts | 69 +++++++++++++++++++ .../src/utils/get-text-value.ts | 68 ++++++++++++++++++ 6 files changed, 294 insertions(+), 1 deletion(-) create mode 100644 jest/polyfills.ts create mode 100644 packages/@headlessui-react/src/utils/get-text-value.test.ts create mode 100644 packages/@headlessui-react/src/utils/get-text-value.ts create mode 100644 packages/@headlessui-vue/src/utils/get-text-value.test.ts create mode 100644 packages/@headlessui-vue/src/utils/get-text-value.ts diff --git a/jest/create-jest-config.cjs b/jest/create-jest-config.cjs index 3ab2429e19..63e9394dbe 100644 --- a/jest/create-jest-config.cjs +++ b/jest/create-jest-config.cjs @@ -3,7 +3,11 @@ module.exports = function createJestConfig(root, options) { return Object.assign( { rootDir: root, - setupFilesAfterEnv: ['../../jest/custom-matchers.ts', ...setupFilesAfterEnv], + setupFilesAfterEnv: [ + '../../jest/custom-matchers.ts', + '../../jest/polyfills.ts', + ...setupFilesAfterEnv, + ], transform: { '^.+\\.(t|j)sx?$': '@swc/jest', ...transform, diff --git a/jest/polyfills.ts b/jest/polyfills.ts new file mode 100644 index 0000000000..f928491855 --- /dev/null +++ b/jest/polyfills.ts @@ -0,0 +1,15 @@ +// JSDOM Doesn't implement innerText yet: https://github.com/jsdom/jsdom/issues/1245 +// So this is a hacky way of implementing it using `textContent`. +// Real implementation doesn't use textContent because: +// > textContent gets the content of all elements, including