@bbc/psammead-test-helpers

中文文档
6.0.5发布于 2021/08/27Apache-2.0ESM + CJS零依赖近 30 天下载 9072

A collection of helper methods for implementing Jest snapshot tests for emotion, required by many Psammead components.

原始使用文档
文档目录7 节
  1. Exported Functions
  2. Installation
  3. Usage
  4. Roadmap
  5. Contributing
  6. Code of Conduct
  7. License

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

NameArgumentsDescription
shouldMatchSnapshottitle, componentRenders 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.
matchSnapshotAsynccomponentRenders 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.
isNulltitle, componentRenders 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.
testUtilityPackagesactualExports, expectedExports, utilityNameValidates 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' }.
setWindowValuekey, valueAllows you to set variables on the window (eg. location) that are normally not writable
resetWindowValuekey, valueAllows you to reset the WindowValues that are previously overwritten by the setWindowValue function
suppressPropWarningswarningsSuppresses 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.

Code of Conduct

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.

版本与发布记录

@bbc/psammead-test-helpers 共发布 40 个版本,首次发布于 2018/12/03;过去 12 个月发布了 0 个版本。

版本发布日期距今
6.0.5latest2021/08/275 年前
6.0.42021/03/105 年前
6.0.32021/03/025 年前
6.0.22021/02/225 年前
6.0.12021/02/045 年前
6.0.02021/01/155 年前

关于 @bbc/psammead-test-helpers 的常见问题

@bbc/psammead-test-helpers 是什么?

A collection of helper methods for implementing Jest snapshot tests for emotion, required by many Psammead components.

如何安装 @bbc/psammead-test-helpers?

在项目目录运行 npm install @bbc/psammead-test-helpers,或使用 pnpm add / yarn add / bun add。

@bbc/psammead-test-helpers 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/bbc__psammead-test-helpers 是否存在。

@bbc/psammead-test-helpers 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bbc/psammead-test-helpers 可以商用吗?

@bbc/psammead-test-helpers 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@bbc/psammead-test-helpers 的下载量有多少?

根据 npm 官方下载统计,@bbc/psammead-test-helpers 在 2026/10/08 – 2026/11/06 这 30 天内被下载 9,072 次,日均约 302 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bbc/psammead-test-helpers 还在维护吗?

最新版本 6.0.5 发布于 2021/08/27(5 年前);至今共发布 40 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/12/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。