Coder Social home page Coder Social logo

tanem / jest-prettyhtml-matchers Goto Github PK

View Code? Open in Web Editor NEW
1.0 4.0 0.0 3.23 MB

:black_joker: Custom Jest snapshot matchers that use prettyhtml to format strings.

Home Page: https://npm.im/jest-prettyhtml-matchers

License: MIT License

JavaScript 4.55% TypeScript 95.45%
custom javascript jest matchers prettyhtml snapshot testing typescript

jest-prettyhtml-matchers's Introduction

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

jest-prettyhtml-matchers's People

Contributors

dependabot[bot] avatar renovate-bot avatar renovate[bot] avatar tanem avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

jest-prettyhtml-matchers's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • Lock file maintenance

Pending Status Checks

These updates await pending status checks. To force their creation now, click the checkbox below.

  • Update typescript-eslint monorepo to v7.16.1 (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • styfle/cancel-workflow-action 0.12.1
  • actions/checkout v4
  • actions/setup-node v4
  • codecov/codecov-action v4
npm
package.json
  • @starptech/prettyhtml ^0.10.0
  • @types/fs-extra 11.0.4
  • @types/jest 29.5.12
  • @typescript-eslint/eslint-plugin 7.16.0
  • @typescript-eslint/parser 7.16.0
  • del 6.1.1
  • del-cli 5.1.0
  • eslint 8.57.0
  • eslint-config-prettier 9.1.0
  • fs-extra 11.2.0
  • jest 29.7.0
  • jest-snapshot 29.7.0
  • npm-run-all2 6.2.2
  • prettier 3.3.3
  • tanem-scripts 7.0.27
  • ts-jest 29.2.2
  • ts-node 10.9.2
  • typescript 5.5.3
  • jest ^25.0.0 || ^26.0.0 || ^27.0.0 || ^28.0.0 || ^29.0.0
  • jest-snapshot ^25.0.0 || ^26.0.0 || ^27.0.0 || ^28.0.0 || ^29.0.0
nvm
.nvmrc

  • Check this box to trigger a request for Renovate to run again on this repository

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

File: renovate.json
Error type: The renovate configuration file contains some invalid settings
Message: Invalid regExp for packageRules[2].packagePatterns: ^jest``

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.