1.17.14 • Published 1 month ago

jest-prettyhtml-matchers v1.17.14

Weekly downloads
371
License
MIT
Repository
github
Last release
1 month ago

jest-prettyhtml-matchers

npm version build status coverage status npm downloads

Custom Jest snapshot matchers that use prettyhtml to format strings.

Basic Usage | API | Installation | License

Basic Usage

First, add the custom matchers to Jest. A convenient way to do this is via a setup file included in setupFilesAfterEnv:

// setupJest.js
import { createPrettyHtmlMatchers } from 'jest-prettyhtml-matchers'
expect.extend(createPrettyHtmlMatchers())

Note for TypeScript users: To ensure the global jest declaration is augmented correctly, this file should be included via your TypeScript configuration. There's an example of this setup in tanem/react-svg.

Now you can use the custom matchers in your tests:

expect(string).toMatchPrettyHtmlSnapshot()
expect(string).toMatchInlinePrettyHtmlSnapshot()

API

createPrettyHtmlMatchers(options?: PrettyHtmlOptions)

Generates the custom matchers so that they can be added to Jest.

Arguments

  • options - Optional An object containing prettyhtml options. If options is not provided, prettyhtml's default options will be used when formatting strings. If options is provided, it will be merged with prettyhtml's default options, and the merged options will be used when formatting strings. In both cases, the options will apply to all usages of the custom matchers, but can be overridden in the matcher calls themselves.

Examples

createPrettyHtmlMatchers()
createPrettyHtmlMatchers({ singleQuote: false }))

toMatchPrettyHtmlSnapshot(options?: PrettyHtmlOptions, hint?: string)

Ensures that a value formatted with prettyhtml matches the most recent snapshot.

Arguments

  • options - Optional An object containing prettyhtml options. These options take precedence over options defined globally in createPrettyHtmlMatchers.
  • hint - Optional A string that is appended to the test name.

Examples

expect(string).toMatchPrettyHtmlSnapshot()
expect(string).toMatchPrettyHtmlSnapshot('testName')
expect(string).toMatchPrettyHtmlSnapshot({ singleQuote: false })
expect(string).toMatchPrettyHtmlSnapshot({ singleQuote: false }, 'testName')

toMatchInlinePrettyHtmlSnapshot(options?: PrettyHtmlOptions, inlineSnapshot?: string)

Ensures that a value formatted with prettyhtml matches the most recent snapshot.

Arguments

  • options - Optional An object containing prettyhtml options. These options take precedence over options defined globally in createPrettyHtmlMatchers.
  • inlineSnapshot - Optional Jest adds this string to the matcher in the test file (instead of an external .snap file) the first time that the test runs.

Examples

expect(string).toMatchInlinePrettyHtmlSnapshot()
expect(string).toMatchInlinePrettyHtmlSnapshot({ singleQuote: false })

Installation

$ npm install -D jest-prettyhtml-matchers

License

MIT

1.17.14

1 month ago

1.17.13

3 months ago

1.17.12

5 months ago

1.17.11

5 months ago

1.17.10

6 months ago

1.17.6

7 months ago

1.17.5

8 months ago

1.17.9

7 months ago

1.17.8

7 months ago

1.17.7

7 months ago

1.17.4

8 months ago

1.17.3

8 months ago

1.16.10

11 months ago

1.16.12

10 months ago

1.16.11

10 months ago

1.16.7

11 months ago

1.16.6

12 months ago

1.16.9

11 months ago

1.16.8

11 months ago

1.17.2

9 months ago

1.17.1

9 months ago

1.17.0

9 months ago

1.16.3

1 year ago

1.16.2

1 year ago

1.16.1

1 year ago

1.16.5

12 months ago

1.16.4

12 months ago

1.14.9

1 year ago

1.14.8

1 year ago

1.14.7

1 year ago

1.15.0

1 year ago

1.15.4

1 year ago

1.15.3

1 year ago

1.15.2

1 year ago

1.15.1

1 year ago

1.15.6

1 year ago

1.15.5

1 year ago

1.16.0

1 year ago

1.14.1

1 year ago

1.14.0

1 year ago

1.14.5

1 year ago

1.14.4

1 year ago

1.14.3

1 year ago

1.14.2

1 year ago

1.14.6

1 year ago

1.13.1

1 year ago

1.13.0

2 years ago

1.11.12

2 years ago

1.11.11

2 years ago

1.12.1

2 years ago

1.12.0

2 years ago

1.11.10

2 years ago

1.11.4

2 years ago

1.11.3

2 years ago

1.11.2

2 years ago

1.11.1

2 years ago

1.11.8

2 years ago

1.11.7

2 years ago

1.11.6

2 years ago

1.11.5

2 years ago

1.11.9

2 years ago

1.10.7

2 years ago

1.11.0

2 years ago

1.10.5

2 years ago

1.10.4

2 years ago

1.10.3

2 years ago

1.10.2

2 years ago

1.10.6

2 years ago

1.9.1

2 years ago

1.9.0

2 years ago

1.10.1

2 years ago

1.10.0

2 years ago

1.9.4

2 years ago

1.9.3

2 years ago

1.9.2

2 years ago

1.8.6

2 years ago

1.8.5

2 years ago

1.8.4

2 years ago

1.8.2

2 years ago

1.8.1

2 years ago

1.8.0

2 years ago

1.8.3

2 years ago

1.7.5

3 years ago

1.7.4

3 years ago

1.7.3

3 years ago

1.7.2

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.10

3 years ago

1.5.9

3 years ago

1.5.8

3 years ago

1.5.7

3 years ago

1.5.6

3 years ago

1.5.5

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.16

3 years ago

1.4.15

3 years ago

1.4.14

3 years ago

1.4.13

3 years ago

1.4.12

3 years ago

1.4.11

3 years ago

1.4.10

3 years ago

1.4.9

3 years ago

1.4.8

3 years ago

1.4.7

3 years ago

1.4.6

3 years ago

1.4.5

3 years ago

1.4.4

3 years ago

1.4.3

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.0

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.69

4 years ago

1.0.68

4 years ago

1.0.67

4 years ago

1.0.66

4 years ago

1.0.65

4 years ago

1.0.64

4 years ago

1.0.63

4 years ago

1.0.62

4 years ago

1.0.61

4 years ago

1.0.60

4 years ago

1.0.59

4 years ago

1.0.58

4 years ago

1.0.57

4 years ago

1.0.56

4 years ago

1.0.55

4 years ago

1.0.54

4 years ago

1.0.53

4 years ago

1.0.52

4 years ago

1.0.50

4 years ago

1.0.49

4 years ago

1.0.48

4 years ago

1.0.47

4 years ago

1.0.46

4 years ago

1.0.45

4 years ago

1.0.44

4 years ago

1.0.43

5 years ago

1.0.42

5 years ago

1.0.41

5 years ago

1.0.40

5 years ago

1.0.39

5 years ago

1.0.38

5 years ago

1.0.37

5 years ago

1.0.36

5 years ago

1.0.35

5 years ago

1.0.34

5 years ago

1.0.33

5 years ago

1.0.32

5 years ago

1.0.31

5 years ago

1.0.30

5 years ago

1.0.29

5 years ago

1.0.28

5 years ago

1.0.27

5 years ago

1.0.26

5 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago