From 15b5006df48ba4083f4238b8896f507516cb0c52 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Sat, 13 Mar 2021 01:33:13 +0100 Subject: [PATCH] test fixes --- src/components/Layout.jsx | 2 +- src/components/atoms/HostnameCheck.jsx | 16 ++++++---------- tests/jest.config.js | 3 ++- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/components/Layout.jsx b/src/components/Layout.jsx index b2c0ecc..97940aa 100644 --- a/src/components/Layout.jsx +++ b/src/components/Layout.jsx @@ -4,7 +4,7 @@ import posed, { PoseGroup } from 'react-pose' import { fadeIn } from './atoms/Transitions' import Typekit from './atoms/Typekit' import HostnameCheck from './atoms/HostnameCheck' -import ThemeSwitch from './molecules/ThemeSwitch' +// import ThemeSwitch from './molecules/ThemeSwitch' import Header from './organisms/Header' import Footer from './organisms/Footer' import { screen } from './Layout.module.css' diff --git a/src/components/atoms/HostnameCheck.jsx b/src/components/atoms/HostnameCheck.jsx index 47bd904..6a11a82 100644 --- a/src/components/atoms/HostnameCheck.jsx +++ b/src/components/atoms/HostnameCheck.jsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react' +import React, { useCallback, useEffect, useState } from 'react' import PropTypes from 'prop-types' import { Helmet } from 'react-helmet' import { hostnameInfo } from './HostnameCheck.module.css' @@ -11,16 +11,12 @@ export default function HostnameCheck({ allowedHosts }) { // default to true so SSR builds never show the banner const [isAllowedHost, setIsAllowedHost] = useState(true) - const checkAllowedHost = () => { - if (typeof window !== 'undefined' && window.location) { - return allowedHosts.includes(window.location.hostname) - } - } - useEffect(() => { - const isAllowedHost = checkAllowedHost() - setIsAllowedHost(isAllowedHost) - }, []) + if (typeof window !== 'undefined' && window.location) { + const isAllowedHost = allowedHosts.includes(window.location.hostname) + setIsAllowedHost(isAllowedHost) + } + }, [allowedHosts]) return !isAllowedHost ? ( <> diff --git a/tests/jest.config.js b/tests/jest.config.js index 40f340d..64d1f14 100644 --- a/tests/jest.config.js +++ b/tests/jest.config.js @@ -4,7 +4,8 @@ module.exports = { '.+\\.(css|styl|less|sass|scss)$': 'identity-obj-proxy', '.+\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '/tests/__mocks__/file-mock.js', - '\\.svg': '/tests/__mocks__/svgr-mock.js' + '\\.svg': '/tests/__mocks__/svgr-mock.js', + '^@reach/router(.*)': '/node_modules/@gatsbyjs/reach-router$1' }, testPathIgnorePatterns: [ 'node_modules',