Get started with expect CDN

MIT licensed

JSs expect library offers chainable assertions for clearer tests.

Tags:
  • expect
  • assert
  • test
  • spec

Stable version

Copied!

How to start using expect CDN


<!DOCTYPE html>
<html>
<head>
  <meta name="description" content="Example of using Expect.js library">
  <title>Get started with expect CDN - cdnhub.io</title>
  <script src="https://cdn.cdnhub.io/expect/29.7.0/expect.min.js"></script>
</head>
<body>
  <button id="test-button">Click me</button>

  <script>
    const expect = require('expect');

    document.addEventListener('DOMContentLoaded', () => {
      const testButton = document.getElementById('test-button');

      testButton.addEventListener('click', () => {
        const textBeforeClick = testButton.textContent;

        expect(textBeforeClick).toBe('Click me');

        testButton.click();

        const textAfterClick = testButton.textContent;

        expect(textAfterClick).not.toBe('Click me');
        expect(textAfterClick).toMatch(/^[A-Z]\w*$/); // Expect the text to start with a capital letter and be followed by one or more word characters
      });
    });
  </script>
</body>
</html>

All versions

1.10.0 1.11.0 1.11.1 1.12.0 1.12.1 1.12.2 1.13.0 1.13.1 1.13.2 1.13.3 1.13.4 1.14.0 1.15.0 1.15.1 1.15.2 1.16.0 1.17.0 1.18.0 1.19.0 1.20.0 1.20.1 1.20.2 21.0.0 21.0.0-beta.1 21.0.2 21.1.0 21.2.0 21.2.1 21.3.0-alpha.1e3ee68e 21.3.0-alpha.eff7a1cf 21.3.0-beta.1 21.3.0-beta.10 21.3.0-beta.11 21.3.0-beta.12 21.3.0-beta.13 21.3.0-beta.14 21.3.0-beta.15 21.3.0-beta.2 21.3.0-beta.3 21.3.0-beta.4 21.3.0-beta.5 21.3.0-beta.6 21.3.0-beta.7 21.3.0-beta.8 21.3.0-beta.9 22.0.0 22.0.1 22.0.2 22.0.3 22.0.5 22.0.6 22.1.0 22.2.0 22.2.2 22.3.0 22.4.0 22.4.3 23.0.0 23.0.0-alpha.0 23.0.0-alpha.1 23.0.0-alpha.2 23.0.0-alpha.3r 23.0.0-alpha.4 23.0.0-alpha.5 23.0.0-alpha.5r 23.0.0-alpha.6r 23.0.0-alpha.7 23.0.0-beta.0 23.0.0-beta.1 23.0.0-beta.2 23.0.0-beta.3r 23.0.0-charlie.0 23.0.0-charlie.1 23.0.0-charlie.2 23.0.0-charlie.3 23.0.0-charlie.4 23.0.1 23.1.0 23.2.0 23.3.0 23.4.0 23.5.0 23.6.0 24.0.0 24.0.0-alpha.0 24.0.0-alpha.1 24.0.0-alpha.10 24.0.0-alpha.11 24.0.0-alpha.12 24.0.0-alpha.13 24.0.0-alpha.15 24.0.0-alpha.16 24.0.0-alpha.2 24.0.0-alpha.4 24.0.0-alpha.5 24.0.0-alpha.6 24.0.0-alpha.7 24.0.0-alpha.8 24.0.0-alpha.9 24.1.0 24.2.0-alpha.0 24.3.0 24.3.1 24.4.0 24.5.0 24.6.0 24.7.0 24.7.1 24.8.0 24.9.0 25.0.0 25.1.0 25.2.0 25.2.0-alpha.86 25.2.1 25.2.1-alpha.1 25.2.1-alpha.2 25.2.3 25.2.4 25.2.6 25.2.7 25.3.0 25.4.0 25.5.0 26.0.0 26.0.0-alpha.0 26.0.0-alpha.1 26.0.0-alpha.2 26.0.1 26.0.1-alpha.0 26.1.0 26.2.0 26.3.0 26.4.0 26.4.1 26.4.2 26.5.0 26.5.2 26.5.3 26.6.0 26.6.1 26.6.2 27.0.0 27.0.0-next.0 27.0.0-next.1 27.0.0-next.10 27.0.0-next.11 27.0.0-next.3 27.0.0-next.5 27.0.0-next.6 27.0.0-next.7 27.0.0-next.8 27.0.0-next.9 27.0.1 27.0.2 27.0.6 27.1.0 27.1.1 27.2.0 27.2.1 27.2.2 27.2.3 27.2.4 27.2.5 27.3.0 27.3.1 27.4.0 27.4.1 27.4.2 27.4.6 27.5.0 27.5.1 28.0.0 28.0.0-alpha.0 28.0.0-alpha.1 28.0.0-alpha.2 28.0.0-alpha.3 28.0.0-alpha.4 28.0.0-alpha.5 28.0.0-alpha.6 28.0.0-alpha.7 28.0.0-alpha.8 28.0.0-alpha.9 28.0.1 28.0.2 28.1.0 28.1.1 28.1.3 29.0.0 29.0.0-alpha.0 29.0.0-alpha.1 29.0.0-alpha.3 29.0.0-alpha.4 29.0.0-alpha.6 29.0.1 29.0.2 29.0.3 29.1.0 29.1.2 29.2.0 29.2.1 29.2.2 29.3.0 29.3.1 29.4.0 29.4.1 29.4.2 29.4.3 29.5.0 29.6.0 29.6.1 29.6.2 29.6.3 29.6.4 *** 29.7.0 30.0.0-alpha.1 30.0.0-alpha.2 30.0.0-alpha.3 30.0.0-alpha.4 30.0.0-alpha.5 30.0.0-alpha.6