GithubHelp home page GithubHelp logo

trueadm / jest Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jestjs/jest

2.0 3.0 0.0 12.52 MB

๐Ÿƒ Painless JavaScript Testing.

Home Page: http://facebook.github.io/jest/

License: Other

JavaScript 96.41% CSS 3.08% TypeScript 0.03% PHP 0.48%

jest's Introduction

Jest

CircleCI Build Status Travis Build Status Windows Build Status npm version

๐Ÿƒ Painless JavaScript Testing

  • ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป Easy Setup: Jest is a complete and easy to set up JavaScript testing solution. In fact, Jest 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.

Getting Started

<generated_getting_started_start /> Install Jest using npm:

npm install --save-dev jest

Let's get started by writing a test for a hypothetical function that adds two numbers. First, create a sum.js file:

function sum(a, b) {
  return a + b;
}
module.exports = sum;

Then, create a file named sum.test.js. This will contain our actual test:

const sum = require('./sum');

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

Add the following section to your package.json:

"scripts": {
  "test": "jest"
}

Finally, run npm test and Jest will print this message:

PASS  ./sum.test.js
โœ“ adds 1 + 2 to equal 3 (5ms)

You just successfully wrote your first test using Jest!

This test used expect and toBe to test that two values were exactly identical. To learn about the other things that Jest can test, see Using Matchers.

Additional Configuration

Using Babel

To use Babel, install the babel-jest and regenerator-runtime packages:

npm install --save-dev babel-jest regenerator-runtime

Note: Explicitly installing regenerator-runtime is not needed if you use npm 3 or 4 or Yarn

Don't forget to add a .babelrc file in your project's root folder. For example, if you are using ES6 and React.js with the babel-preset-es2015 and babel-preset-react presets:

{
  "presets": ["es2015", "react"]
}

You are now set up to use all ES6 features and React specific syntax.

Note: If you are using a more complicated Babel configuration, using Babel's env option, keep in mind that Jest will automatically define NODE_ENV as test. It will not use development section like Babel does by default when no NODE_ENV is set.

Using webpack

Jest can be used in projects that use webpack to manage assets, styles, and compilation. webpack does offer some unique challenges over other tools. Refer to the webpack guide to get started.

Using TypeScript

To use TypeScript in your tests, install the ts-jest package:

npm install --save-dev ts-jest

then modify your package.json so the jest section looks something like:

{
  "jest": {
    "transform": {
      ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js"
    ]
  }
}

<generated_getting_started_end />

Documentation

Learn more about using Jest at http://facebook.github.io/jest

Contributing

Send issues and pull requests with your ideas. For more information about contributing PRs and issues, see our Contribution Guidelines.

Good First Task is a great starting point for PRs.

jest's People

Contributors

aaronabramov avatar amasad avatar clentfort avatar cpojer avatar daniel15 avatar dmitrysoshnikov avatar emmenko avatar forbeslindesay avatar gaearon avatar hankhsiao avatar hramos avatar ide avatar jbonta avatar jeffmo avatar kentaromiura avatar leebyron avatar maximderbin avatar orta avatar pedrottimark avatar philvargas avatar rogeliog avatar sampepose avatar sophiebits avatar stephnr avatar thymikee avatar vjeux avatar wtgtybhertgeghgtwtg avatar yungsters avatar zouxuoz avatar zpao avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

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.