From a844bf362da15036e7c118b8a362cb3f019956e0 Mon Sep 17 00:00:00 2001 From: Ingo Oppermann Date: Wed, 16 Nov 2022 16:45:02 +0100 Subject: [PATCH] Add some testing hints --- src/utils/testing.js | 26 ++++++++++++++++++++++++++ src/views/Edit/Sources/Network.test.js | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/utils/testing.js b/src/utils/testing.js index 2ed72c9..23827d4 100644 --- a/src/utils/testing.js +++ b/src/utils/testing.js @@ -6,6 +6,32 @@ import { HashRouter as DOMRouter } from 'react-router-dom'; import theme from '../theme'; import I18n from '../I18n'; +/* +This is wrapper for the render method in order to provide all required providers and +not to repeat them for each test. + +If you want to debug a test by having a look at the current output of the component, +simply import the "screen" object from this file and use the "debug()" method: + + test('displays the header and paragraph text', () => { + render() + screen.debug() + }) + +or of a specific element in the component: + + test('displays the header and paragraph text', () => { + render() + const header = screen.getByRole('heading', { name: /travel anywhere/i }) + screen.debug(header) + }) + +More about "render" and "screen" on https://testing-library.com/docs + +For testing certain conditions, check out https://jestjs.io/docs/expect and for +running tests, check out https://jestjs.io/docs/api. +*/ + const AllTheProviders = ({ children }) => { return ( diff --git a/src/views/Edit/Sources/Network.test.js b/src/views/Edit/Sources/Network.test.js index 9e4f3fb..d357cc9 100644 --- a/src/views/Edit/Sources/Network.test.js +++ b/src/views/Edit/Sources/Network.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { render, fireEvent, screen } from '../../../utils/testing'; +import { render, fireEvent } from '../../../utils/testing'; import '@testing-library/jest-dom'; import * as Network from './Network';