b707cd28f1
* feat(test-utils): move the toEmitValue/s jest matchers to test-utils and add test script * chore(jest): update configs to use matchers from test-utils package * ci(frontend-tests): hook up packages tests * fix(test-utils): re-export matchers from index.ts so packages that include setupTests don't error * ci(pr-frontend-unit-tests): add frontend-packages-unit-tests to list of required unit tests * Update packages/grafana-test-utils/README.md Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> --------- Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
25 lines
905 B
Markdown
25 lines
905 B
Markdown
# Grafana test utils
|
|
|
|
This package is a collection of test utils and a mock API (using MSW) for use with core Grafana UI development.
|
|
|
|
## Matchers
|
|
|
|
To add the matchers to your Jest config, import them then extend `expect`. This should be done in the `setupFilesAfterEnv` file declared in `jest.config.{js,ts}`.
|
|
|
|
```ts
|
|
// setupTests.ts
|
|
import { matchers } from '@grafana/test-utils';
|
|
|
|
expect.extend(matchers);
|
|
```
|
|
|
|
Included in this package are the following matchers:
|
|
|
|
### `toEmitValues`
|
|
|
|
Tests that an Observable emits the expected values in the correct order. This matcher collects all emitted values (including errors) and compares them against the expected array using deep equality.
|
|
|
|
### `toEmitValuesWith`
|
|
|
|
Tests that an Observable emits values that satisfy custom expectations. This matcher collects all emitted values and passes them to a callback function where you can perform custom assertions.
|