jest-expect-standalone

24.0.2 • Public • Published

Jest Expect Standalone

Jest Expect Standalone Library. Use the expect package from the facebook/jest project in the browser without any troubles.

What and why

Previously, the expect library was maintained over at mjackson/expect. However, the author decided to donate the project over to facebook/jest. See more information about this process in facebook/jest/issues/1679. Before the donation, the expect library was hosted on various CDNs, and you could easily include it as a script tag in some HTML file. It was usually done for quick testing/prototyping of code in online tools such as JSFiddle, JS Bin, or Plunker. One good example of expect usage for educational purposes is in the series of lectures Getting Started with Redux - Egghead by Dan Abramov.

After the handover of expect library, it became almost impossible to quickly include it in HTML code as a script tag. One possibility of how it can be achieved is illustrated in the JS Bin sample jsbin/nucimeceve. However, the method is cumbersome, and the result is slow. This is partly because facebook/jest uses expect as an internal dependency, and does not bundle it as a standalone UMD module.

This project intends to make available expect library as a standalone library for easy inclusion inside the browser via a script tag. jest-expect-standalone will be made available via CDN, and updated each time facebook/jest project updates their internal expect library.

Usage

Include jest-expect-standalone as a script tag, and you will have the library available via window.expect.

<script src="https://unpkg.com/jest-expect-standalone@latest/dist/expect.min.js"></script>

See sample JS Bin jsbin/wapokahaxe.

Or copy and paste the following HTML code in your editor, and hack away:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Running jest-expect-standalone</title>
  <script src="https://unpkg.com/jest-expect-standalone@latest/dist/expect.min.js"></script>
  <script>
    try {
      expect(true).toEqual(false);
      console.log('Test #1 passed!');
    } catch (err) {
      console.log(err);
      console.log('Test #1 failed!');
    }
    try {
      expect(2).toEqual(2);
      console.log('Test #2 passed!');
    } catch (err) {
      console.log(err);
      console.log('Test #2 failed!');
    }
  </script>
</head>
<body>

</body>
</html>

Building & running tests

To hack away on this project, clone this repository and change to it's root directory. After installing NPM modules with npm install, you have the following commands available:

npm run build
npm run test

License

This project is licensed under the MIT License. See LICENSE for more details.

Enjoy ;)

Readme

Keywords

none

Package Sidebar

Install

npm i jest-expect-standalone

Weekly Downloads

77

Version

24.0.2

License

MIT

Unpacked Size

361 kB

Total Files

4

Last publish

Collaborators

  • valera_rozuvan