From 238ff3b19b8da756285a306defadc00ae163b908 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Sun, 11 Dec 2022 15:35:06 +0100 Subject: [PATCH] maint: Maintain own test setup config. Don't extend from @patternslib/patternslib for setting up tests. The config files are not included in the npm package distributions anymore. --- jest.config.js | 2 +- src/setup-tests.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index 5fbdd9a91..1c1b6c6ff 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,5 @@ const path = require("path"); -const config = require("@patternslib/patternslib/jest.config.js"); +const config = require("@patternslib/dev/jest.config.js"); config.setupFilesAfterEnv.push(path.resolve(__dirname, "./src/setup-tests.js")); diff --git a/src/setup-tests.js b/src/setup-tests.js index e69de29bb..20ad5b66e 100644 --- a/src/setup-tests.js +++ b/src/setup-tests.js @@ -0,0 +1,21 @@ +// Extra test setup. + +import jquery from "jquery"; +global.$ = global.jQuery = jquery; + +jquery.expr.pseudos.visible = function () { + // Fix jQuery ":visible" selector always returns false in JSDOM. + // https://github.com/jsdom/jsdom/issues/1048#issuecomment-401599392 + return true; +}; + +// Do not output error messages +import logging from "@patternslib/patternslib/core/logging"; +logging.setLevel(50); +// level: FATAL + +// patch dom.is_visible to not rely on jest-unavailable offsetWidth/Height +import dom from "@patternslib/patternslib/core/dom"; +dom.is_visible = (el) => { + return !el.hidden && el.style.display !== "none"; +};