Convert Figma logo to code with AI

jest-community logojest-extended

Additional Jest matchers 🃏💪

2,317
223
2,317
139

Top Related Projects

44,166

Delightful JavaScript Testing.

20,731

Node.js test runner that lets you develop with confidence 🚀

22,590

☕️ simple, flexible, fun javascript test framework for node.js & the browser

15,742

Simple JavaScript testing framework for browsers and node.js

46,847

Fast, easy and reliable testing for anything that runs in a browser.

12,902

Next generation testing framework powered by Vite.

Quick Overview

Jest Extended is a library that enhances Jest, the popular JavaScript testing framework, by providing additional matchers and utilities. It aims to make writing tests more expressive and reduce boilerplate code, offering a wide range of custom matchers that cover common testing scenarios.

Pros

  • Extensive set of additional matchers, improving test readability and expressiveness
  • Easy integration with existing Jest projects
  • Regularly maintained and updated
  • Comprehensive documentation with examples for each matcher

Cons

  • Potential learning curve for developers unfamiliar with the additional matchers
  • May increase test bundle size slightly
  • Some matchers might overlap with built-in Jest functionality
  • Dependency on Jest updates and compatibility

Code Examples

  1. Testing array contents:
expect([1, 2, 3]).toIncludeAllMembers([1, 2]);
  1. Checking object properties:
expect({ name: 'John', age: 30 }).toContainKeys(['name', 'age']);
  1. Verifying function behavior:
const fn = jest.fn();
expect(fn).toHaveBeenCalledBefore(anotherFn);
  1. Testing string patterns:
expect('hello world').toStartWith('hello');

Getting Started

  1. Install Jest Extended:
npm install --save-dev jest-extended
  1. Add Jest Extended to your Jest configuration:
// jest.config.js
module.exports = {
  setupFilesAfterEnv: ['jest-extended/all'],
};
  1. Start using the additional matchers in your tests:
test('array contains specific elements', () => {
  expect([1, 2, 3, 4]).toInclude(3);
  expect([{ id: 1 }, { id: 2 }]).toContainEqual({ id: 1 });
});

Competitor Comparisons

44,166

Delightful JavaScript Testing.

Pros of Jest

  • Comprehensive testing framework with built-in assertion library
  • Extensive documentation and large community support
  • Integrated code coverage and mocking capabilities

Cons of Jest

  • Larger package size and potentially slower setup time
  • Less flexibility for custom matchers without additional plugins
  • May have a steeper learning curve for beginners

Code Comparison

Jest:

test('adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3);
});

Jest Extended:

test('array contains only numbers', () => {
  expect([1, 2, 3]).toBeArrayOfNumbers();
});

Key Differences

  • Jest Extended is an add-on to Jest, providing additional matchers
  • Jest Extended focuses on enhancing assertion capabilities
  • Jest is a complete testing solution, while Jest Extended complements it

When to Use

  • Use Jest for a full-featured testing framework out of the box
  • Choose Jest Extended when you need more specific or expressive matchers
  • Consider using both together for a comprehensive testing experience

Community and Maintenance

  • Jest has a larger community and more frequent updates
  • Jest Extended is maintained by the community and may have slower release cycles

Integration

Jest Extended can be easily integrated with Jest:

import * as matchers from 'jest-extended';
expect.extend(matchers);

This combination provides the robustness of Jest with the additional matchers from Jest Extended, offering a powerful testing solution for JavaScript projects.

20,731

Node.js test runner that lets you develop with confidence 🚀

Pros of AVA

  • Simpler and more lightweight testing framework
  • Runs tests concurrently, potentially faster execution
  • Encourages writing smaller, more focused tests

Cons of AVA

  • Smaller ecosystem and community compared to Jest
  • Less built-in functionality, may require additional plugins
  • Steeper learning curve for developers familiar with Jest

Code Comparison

AVA:

import test from 'ava';

test('foo', t => {
    t.pass();
});

Jest Extended:

describe('foo', () => {
    it('should pass', () => {
        expect(true).toBe(true);
    });
});

Key Differences

  • AVA uses a more minimalist syntax, while Jest Extended builds upon Jest's familiar structure
  • AVA requires explicit imports, whereas Jest Extended extends Jest's global functions
  • AVA encourages single assertions per test, while Jest allows multiple assertions within a single test case

Use Cases

  • AVA: Ideal for projects prioritizing simplicity and performance
  • Jest Extended: Better suited for projects already using Jest or requiring extensive matchers and utilities

Community and Ecosystem

  • Jest Extended benefits from Jest's large community and extensive plugin ecosystem
  • AVA has a smaller but dedicated community, with a focus on simplicity and performance
22,590

☕️ simple, flexible, fun javascript test framework for node.js & the browser

Pros of Mocha

  • More flexible and customizable testing framework
  • Supports multiple assertion libraries and reporting styles
  • Longer history and larger community support

Cons of Mocha

  • Requires additional setup and configuration for assertions and mocking
  • Less built-in functionality compared to Jest and its extensions
  • Steeper learning curve for beginners

Code Comparison

Mocha:

describe('Array', function() {
  describe('#indexOf()', function() {
    it('should return -1 when the value is not present', function() {
      assert.equal([1, 2, 3].indexOf(4), -1);
    });
  });
});

Jest Extended:

test('array contains specific value', () => {
  expect([1, 2, 3]).toContain(2);
});

test('string matches regex', () => {
  expect('hello world').toMatch(/world/);
});

Jest Extended builds upon Jest's built-in matchers, providing additional assertions and utilities. Mocha, on the other hand, offers a more barebones approach, allowing developers to choose their preferred assertion library and build their test suite from the ground up.

While Mocha provides greater flexibility, Jest Extended offers a more streamlined experience with its extended set of matchers and integration with Jest's ecosystem. The choice between the two depends on project requirements, team preferences, and the desired level of customization in the testing setup.

15,742

Simple JavaScript testing framework for browsers and node.js

Pros of Jasmine

  • Standalone testing framework with built-in assertion library
  • Extensive documentation and large community support
  • Browser-based test runner for easy client-side testing

Cons of Jasmine

  • Less flexible than Jest for custom matchers and extensions
  • Slower test execution compared to Jest
  • Limited built-in mocking capabilities

Code Comparison

Jasmine:

describe('MyComponent', () => {
  it('should have the correct text', () => {
    const component = new MyComponent();
    expect(component.getText()).toBe('Hello, World!');
  });
});

Jest Extended:

describe('MyComponent', () => {
  it('should have the correct text', () => {
    const component = new MyComponent();
    expect(component.getText()).toEqual('Hello, World!');
    expect(component.getText()).toBeString();
  });
});

Jest Extended builds upon Jest's functionality, offering additional matchers like toBeString(). Jasmine provides a similar syntax but with fewer built-in matchers. Jest Extended allows for more expressive and specific assertions, while Jasmine relies on its core set of matchers.

Both frameworks support describe-it syntax for organizing tests, but Jest Extended (via Jest) offers more advanced features like snapshot testing and mock functions out of the box. Jasmine requires additional setup or plugins for similar functionality.

46,847

Fast, easy and reliable testing for anything that runs in a browser.

Pros of Cypress

  • Provides an all-in-one testing framework for end-to-end, integration, and unit tests
  • Offers a rich, interactive test runner with time-travel debugging
  • Supports real-time reloading and automatic waiting for elements

Cons of Cypress

  • Limited to testing web applications and cannot test native mobile apps
  • Requires more setup and configuration compared to Jest Extended
  • Can be slower for running large test suites due to its browser-based approach

Code Comparison

Jest Extended:

expect(value).toBeArray();
expect(value).toBeOneOf([1, 2, 3]);
expect(value).toBeWithin(start, end);

Cypress:

cy.get('.element').should('be.visible');
cy.intercept('GET', '/api/users').as('getUsers');
cy.wait('@getUsers').its('response.statusCode').should('eq', 200);

Summary

Jest Extended is a collection of custom matchers for Jest, focusing on enhancing assertion capabilities. It's lightweight and easy to integrate into existing Jest setups. Cypress, on the other hand, is a comprehensive end-to-end testing framework with a focus on web applications. It provides a more robust set of tools for complex scenarios but may require more resources and setup time. The choice between the two depends on the specific testing needs of the project.

12,902

Next generation testing framework powered by Vite.

Pros of Vitest

  • Faster execution due to Vite-based architecture
  • Native TypeScript support without additional configuration
  • Built-in support for ES modules and modern JavaScript features

Cons of Vitest

  • Smaller ecosystem and community compared to Jest
  • Less mature and potentially less stable than Jest
  • May require additional setup for certain legacy projects

Code Comparison

Jest-extended:

expect(value).toBeArray();
expect(value).toBeOneOf([1, 2, 3]);
expect(value).toContainKey('name');

Vitest:

expect(value).toBeTypeOf('array');
expect([1, 2, 3]).toContain(value);
expect(value).toHaveProperty('name');

Summary

Vitest offers improved performance and modern JavaScript support, making it attractive for new projects. However, Jest-extended benefits from a larger ecosystem and more established community. The choice between them depends on project requirements and team preferences.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

jest-extended

🃏💪

Additional Jest matchers


Build Status Code Coverage version downloads MIT License PRs Welcome Examples

Problem

Jest is an amazing test runner and has some awesome assertion APIs built in by default. However, there are times when having more specific matchers (assertions) would be far more convenient.

Solution

jest-extended aims to add additional matchers to Jest's default ones making it easy to test everything 🙌

Contributing

If you've come here to help contribute - Thanks! Take a look at the contributing docs as a way of getting started.

Installation

See the Installation Guide on Jest Extended documentation site.

Setup

See the Setup instructions on Jest Extended documentation site.

Matchers

See all available matchers and interactive repl on Jest Extended documentation site.

LICENSE

MIT

NPM DownloadsLast 30 Days