jest-browser-globals

25.1.0-beta • Public • Published

jest-browser-globals

Lets you run Jest in a browser. Works with Mocha, which is expected to be in the global scope first.

Makes the following available:

Installation

Run npm install --save-dev jest-browser-globals

In a test runner like Karma, include the built file in the global scope:

// karma.config.js
 
module.exports = {
  frameworks: [ 'mocha' ],
  files: [
    './node_modules/jest-browser-globals/build-es5/index.js'
    // other test files...
  ]
}

To run it in an HTML file, do something like this:

<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8' />
    <link href='https://cdn.jsdelivr.net/npm/mocha@7.0.1/mocha.css' rel='stylesheet' />
    <script src='https://cdn.jsdelivr.net/npm/mocha@7.0.1/mocha.js'></script> 
    <script>mocha.setup('bdd')</script> 
    <script src='./node_modules/jest-browser-globals/build-es5/index.js'></script> 
    <script>
 
      describe('cool thing', function() {
        test('that is works', function() {
          expect(5).toBe(6);
        });
      });
 
    </script> 
  </head>
  <body>
    <div id='mocha'></div>
    <script>mocha.run()</script> 
  </body>
</html>

Fork Info

This package has been created from a fork of the Jest Project. It aggregates the expect, jest-mock, and jest-each packages, attaches them to the window, and does various other things to ensure that Jest runs similarly to how it runs in Node. It also strips out lots of dependencies that only make sense in a Node environment, resulting in a slimmer build.

/jest-browser-globals/

    Package Sidebar

    Install

    npm i jest-browser-globals

    Weekly Downloads

    59

    Version

    25.1.0-beta

    License

    MIT

    Unpacked Size

    135 kB

    Total Files

    3

    Last publish

    Collaborators

    • arshaw