All Projects β†’ smeijer β†’ jest-partial

smeijer / jest-partial

Licence: MIT license
A partial matcher for Jest to simplify validation of complex structures.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to jest-partial

Learn Elm Architecture In Javascript
πŸ¦„ Learn how to build web apps using the Elm Architecture in "vanilla" JavaScript (step-by-step TDD tutorial)!
Stars: ✭ 173 (+723.81%)
Mutual labels:  tests
Manual Testing
This repository contains the General Test Cases for performing Manual Testing on the Web/Mobile application. It also has Test cases related to API Testing. Templates related to Test Plan and BugBash are also updated.
Stars: ✭ 134 (+538.1%)
Mutual labels:  tests
EntityFrameworkCore.AutoFixture
A library aimed to minimize the boilerplate required to unit-test Entity Framework Core code using AutoFixture and in-memory providers.
Stars: ✭ 31 (+47.62%)
Mutual labels:  tests
Supra Api Nodejs
❀️ Node.js REST API boilerplate
Stars: ✭ 182 (+766.67%)
Mutual labels:  tests
Testimo
Testimo is PowerShell module for running health checks for Active Directory (and later on any other server type) against a bunch of different tests
Stars: ✭ 249 (+1085.71%)
Mutual labels:  tests
perseus
Perseus is a set of scripts (docker+javascript) to investigate a distributed database's responsiveness when one of its three nodes is isolated from the peers
Stars: ✭ 49 (+133.33%)
Mutual labels:  tests
Test Time
A helper to control the flow of time
Stars: ✭ 169 (+704.76%)
Mutual labels:  tests
eg
eg delivers clojure.test function tests with conciseness
Stars: ✭ 24 (+14.29%)
Mutual labels:  tests
book-library
πŸ“š A book library app for both Android & IOS ~ Flutter.dev project in Dart
Stars: ✭ 89 (+323.81%)
Mutual labels:  tests
openjpeg-data
Test files for the OpenJPEG libraries and utilities
Stars: ✭ 37 (+76.19%)
Mutual labels:  tests
Ember Native Dom Helpers
Test helpers for your integration tests that fire native events
Stars: ✭ 187 (+790.48%)
Mutual labels:  tests
Brainmonkey
Mocking utility for PHP functions and WordPress plugin API
Stars: ✭ 191 (+809.52%)
Mutual labels:  tests
clonings
A project for learning Clojure, based on rustlings.
Stars: ✭ 32 (+52.38%)
Mutual labels:  tests
Xamarin.forms.mocks
Library for running Xamarin.Forms inside of unit tests
Stars: ✭ 179 (+752.38%)
Mutual labels:  tests
testable
QT/QML Test Runner and Utilities
Stars: ✭ 53 (+152.38%)
Mutual labels:  tests
Acutest
Simple header-only C/C++ unit testing facility.
Stars: ✭ 170 (+709.52%)
Mutual labels:  tests
go-recipes
🦩 Tools for Go projects
Stars: ✭ 2,490 (+11757.14%)
Mutual labels:  tests
7182
Curso 7182 - Refatorando para testes de unidade
Stars: ✭ 21 (+0%)
Mutual labels:  tests
xharness
C# command line tool for running tests on Android / iOS / tvOS devices and simulators
Stars: ✭ 123 (+485.71%)
Mutual labels:  tests
KAI
KAI is a distributed computing model written in modern C++ and is cross-plaftorm. Using custom language translators and an executor, KAI provides full reflection, persistence and cross-process communications without having to modify existing source code. KAI Comes with an automated, generational tricolor garbage collector, and Console- and Windo…
Stars: ✭ 13 (-38.1%)
Mutual labels:  tests

jest-partial

All Contributors

Partial Matcher for Jest Expect

animation of jest-partial matcher

jest-partial asserts that the provided object is a subset of the expected. We don't always want to verify the entire object that has been given. We often just want to protect the properties that we need, and ignore everything else.

Installation

With npm:

npm install --save-dev jest-partial

With yarn:

yarn add -D jest-partial

Setup

Jest >v24

Add jest-partial to your Jest setupFilesAfterEnv configuration. See for help

"jest": {
  "setupFilesAfterEnv": ["jest-partial"]
}

Jest <v23

"jest": {
  "setupTestFrameworkScriptFile": "jest-partial"
}

If you are already using another test framework, like jest-chain, then you should create a test setup file and require each of the frameworks you are using.

For example:

// ./testSetup.js
require('jest-partial');
require('jest-chain');
require('any other test framework libraries you are using');

Then in your Jest config:

"jest": {
  "setupTestFrameworkScriptFile": "./testSetup.js"
}

Typescript

If your editor does not recognise the custom jest-partial matchers, add a global.d.ts file to your project with:

import 'jest-partial';

API

The examples below use the following data object:

const kitchen = {
  version: '1',
  floor: {
    material: 'wood',
    color: 'walnut',
  },
  drawers: [
    {
      contents: [
        { type: 'spoon', count: 4 },
        { type: 'fork', count: 2 },
      ],
    },
  ],
};

.toMatchPartial(object)

case: Our kitchen has multiple drawers, and we just want to know that there is at least one drawer that contains spoons.

expect(kitchen).toMatchPartial({
  drawers: [
    {
      contents: [{ type: 'spoon' }],
    },
  ],
});

case: Our kitchen has multiple drawers, and we want to know that there is a drawer that holds 2 forks.

expect(kitchen).toMatchPartial({
  drawers: [
    {
      contents: [{ type: 'fork', count: 2 }],
    },
  ],
});

case: Our kitchen has multiple drawers, and we want to know that there is a drawer that holds forks and spoons.

expect(kitchen).toMatchPartial({
  drawers: [
    {
      contents: [{ type: 'fork' }, { type: 'spoon' }],
    },
  ],
});

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Stephan Meijer

πŸ€” πŸ’» πŸš‡ 🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].