kibana/packages/kbn-jest-serializers
Tiago Costa e41569b4a6
fix(NA): wrongly spread stripInternal and rootDir configs across packages (#144463)
* chore(NA): remove overrides for rootDir on packages

* chore(NA): replace './target_types' with 'target_types' on packages

* chore(NA): removes stripInternal false configs

* chore(NA): remove unused strip internals
2022-11-03 01:04:55 +00:00
..
src chore(NA): remove src folder requirement from packages (part 2) (#138476) 2022-08-30 15:57:35 +01:00
BUILD.bazel [auto] migrate existing plugin/package configs 2022-10-28 14:06:46 -05:00
index.ts chore(NA): remove src folder requirement from packages (part 2) (#138476) 2022-08-30 15:57:35 +01:00
kibana.jsonc add kibana.jsonc files to existing packages (#138965) 2022-09-08 13:31:57 -07:00
package.json [auto] migrate existing plugin/package configs 2022-10-28 14:06:46 -05:00
README.mdx Initialize ops documentation section (#132262) 2022-05-17 15:22:38 -05:00
tsconfig.json fix(NA): wrongly spread stripInternal and rootDir configs across packages (#144463) 2022-11-03 01:04:55 +00: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());
```