Socket
Socket
Sign inDemoInstall

jest

Package Overview
Dependencies
488
Maintainers
7
Versions
352
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jest

Delightful JavaScript Testing.


Version published
Weekly downloads
23M
decreased by-0.03%
Maintainers
7
Install size
38.6 MB
Created
Weekly downloads
 

Package description

What is jest?

Jest is a delightful JavaScript Testing Framework with a focus on simplicity. It works with projects using: Babel, TypeScript, Node, React, Angular, Vue, and more. It's designed to ensure correctness of any JavaScript codebase. It allows you to write tests with an approachable, familiar, and feature-rich API that gives you results quickly.

What are jest's main functionalities?

Unit Testing

Jest allows you to write unit tests for your JavaScript functions. In this example, a simple test is written to check if the addition of 1 and 2 equals 3.

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

Mocking

Jest provides a powerful mocking library that lets you mock objects, functions, and modules. In this example, an HTTP request is mocked to test the behavior of a function that fetches user data.

jest.mock('../api');

test('should fetch users', () => {
  const users = [{name: 'Bob'}];
  const resp = {data: users};
  axios.get.mockResolvedValue(resp);

  return Users.all().then(data => expect(data).toEqual(users));
});

Snapshot Testing

Snapshot testing enables you to test your UI or any serializable value to ensure it does not change unexpectedly. This example demonstrates testing an object against a snapshot, with some fields expected to match specific types rather than values.

test('will check the matchers and pass', () => {
  const user = {
    createdAt: new Date(),
    id: Math.floor(Math.random() * 20),
    name: 'LeBron James'
  };

  expect(user).toMatchSnapshot({
    createdAt: expect.any(Date),
    id: expect.any(Number)
  });
});

Asynchronous Testing

Jest supports testing of asynchronous code. In this example, an asynchronous function `fetchData` is tested to ensure it resolves with the expected value 'peanut butter'.

test('the data is peanut butter', async () => {
  await expect(fetchData()).resolves.toBe('peanut butter');
});

Other packages similar to jest

Changelog

Source

24.8.0

Features

  • [jest-circus] Bind to Circus events via an optional event handler on any custom env (#8344)
  • [expect] Improve report when matcher fails, part 15 (#8281)
  • [jest-cli] Update --forceExit and "did not exit for one second" message colors (#8329)
  • [expect] Improve report when matcher fails, part 16 (#8306)
  • [jest-runner] Pass docblock pragmas to TestEnvironment constructor (#8320)
  • [docs] Add DynamoDB guide (#8319)
  • [expect] Improve report when matcher fails, part 17 (#8349)
  • [expect] Improve report when matcher fails, part 18 (#8356)
  • [expect] Improve report when matcher fails, part 19 (#8367)

Fixes

  • [jest-each] Fix bug with placeholder values (#8289)
  • [jest-snapshot] Inline snapshots: do not indent empty lines (#8277)
  • [@jest/runtime, @jest/transform] Allow custom transforms for JSON dependencies (#8278)
  • [jest-core] Make detectOpenHandles imply runInBand (#8283)
  • [jest-haste-map] Fix the mapper option which was incorrectly ignored (#8299)
  • [jest-jasmine2] Fix describe return value warning being shown if the describe function throws (#8335)
  • [jest-environment-jsdom] Re-declare global prototype of JSDOMEnvironment (#8352)
  • [jest-snapshot] Handle arrays when merging snapshots (#7089)
  • [expect] Extract names of async and generator functions (#8362)
  • [jest-runtime] Fix virtual mocks not being unmockable after previously being mocked (#8396)
  • [jest-transform] Replace special characters in transform cache filenames to support Windows (#8353)
  • [jest-config] Allow exactly one project (#7498)

Chore & Maintenance

  • [expect] Fix label and add opposite assertion for toEqual tests (#8288)
  • [docs] Mention Jest MongoDB Preset (#8318)
  • [@jest/reporters] Migrate away from istanbul-api (#8294)
  • [*] Delete obsolete emails tag from header comment in test files (#8377)
  • [expect] optimize compare nodes (#8368)
  • [docs] Fix typo in MockFunctionAPI.md (#8406)
  • [LICENSE] Follow copyright header guidelines and delete For Jest software (#8428)

Performance

  • [jest-runtime] Fix module registry memory leak (#8282)
  • [jest-resolve] optimize resolve module path (#8388)
  • [jest-resolve] cache current directory (#8412)
  • [jest-get-type] Simplify checking for primitive (#8416)

Readme

Source

Jest

🃏 Delightful JavaScript Testing

  • 👩🏻‍💻 Developer Ready: Complete and ready to set-up JavaScript testing solution. Works out of the box for any React project.

  • 🏃🏽 Instant Feedback: Failed tests run first. Fast interactive mode can switch between running all tests or only test files related to changed files.

  • 📸 Snapshot Testing: Jest can capture snapshots of React trees or other serializable values to simplify UI testing.

Read More: https://jestjs.io/

Keywords

FAQs

Last updated on 05 May 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc