Skip to content
This repository has been archived by the owner on Aug 13, 2023. It is now read-only.

Latest commit

 

History

History

psammead-test-helpers

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

psammead-test-helpers - Known Vulnerabilities Dependency Status peerDependencies Status GitHub license npm version PRs Welcome

This package provides a collection of helper methods for implementing Jest snapshot tests, required by many Psammead components.

Exported Functions

Name Arguments Description
shouldMatchSnapshot title, component Renders the component using @testing-library/react, converts it to JSON and asserts that it matches the given snapshot, which will be saved in the __snapshots__ directory. The first argument title is the title for the test.
matchSnapshotAsync component Renders the component using @testing-library/react, converts it to JSON and asserts that it matches the given snapshot, which will be saved in the __snapshots__ directory. Unlike shouldMatchSnapshot, it does not create a test, so can be used within any it(...) test.
isNull title, component Renders the component using @testing-library/react, converts it to JSON and asserts that it is null. The first argument title is the title for the test.
testUtilityPackages actualExports, expectedExports, utilityName Validates an imported utility package's exported values against an object of key-value pairs in the form { name_of_export: 'type of export' }, e.g. { shouldMatchSnapshot: 'function' }.
setWindowValue key, value Allows you to set variables on the window (eg. location) that are normally not writable
resetWindowValue key, value Allows you to reset the WindowValues that are previously overwritten by the setWindowValue function
suppressPropWarnings warnings Suppresses predicted prop warnings during tests.

Installation

npm install react react-dom @bbc/psammead-test-helpers --save-dev

Usage

import { shouldMatchSnapshot } from '@bbc/psammead-test-helpers';

shouldMatchSnapshot('should render correctly', <h1>Hello World</h1>);

Roadmap

Contributing

When adding a new export to this utility package the export tests also need to be updated and the export should be adding to the README. When removing an exisiting export from this utility package the export tests need to be updated, the export should be removed from the README and the package version requires a major change (EG: 1.2.1 -> 2.0.0) as this would be considered a breaking change due to functionality being removed.

Psammead is completely open source. We are grateful for any contributions, whether they be new components, bug fixes or general improvements. Please see our primary contributing guide which can be found at the root of the Psammead respository.

We welcome feedback and help on this work. By participating in this project, you agree to abide by the code of conduct. Please take a moment to read it.

License

Psammead is Apache 2.0 licensed.