kibana/packages/kbn-jest-serializers
Luke Elmers b6287708f6
Adds AGPL 3.0 license (#192025)
Updates files outside of x-pack to be triple-licensed under Elastic
License 2.0, AGPL 3.0, or SSPL 1.0.
2024-09-06 19:02:41 -06:00
..
src Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
index.ts Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
kibana.jsonc Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
package.json Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
README.mdx Initialize ops documentation section (#132262) 2022-05-17 15:22:38 -05:00
tsconfig.json Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00

---
id: kibDevDocsOpsJestSerializers
slug: /kibana-dev-docs/ops/jest-serializers
title: "@kbn/jest-serializers"
description: A set of shared serializers to help on writing jest tests
date: 2022-05-17
tags: ['kibana', 'dev', 'contributor', 'operations', 'jest', 'serializers']
---

This package holds a set of shared serializers that may be useful when you're writing jest tests. To use them import the package and call one of the functions, passing the result to `expect.addSnapshotSerializer()`.

## createAbsolutePathSerializer

Replaces a given path starting a string with the provided replacer. Additionally also replaces any `\\` with `/` it founds.

## createStripAnsiSerializer

Strips ansi from a string.

## createRecursiveSerializer

It helps on printing recursive nodes.

## createAnyInstanceSerializer

It serializes any kind of instance inside `<>`. If it is a function calls the function inside the node otherwise prints as `Class.name`.

## createReplaceSerializer

Search for a substring using given Regex or string and replaces with a provided replacer.

## Example

```ts
import { createAbsolutePathSerializer } from '@kbn/jest-serializers'

expect.addSnapshotSerializer(createAbsolutePathSerializer());
```