How to use 'Expect' in JSBin template?

785 views Asked by At

Does anyone know how to use 'expect' function within JSBin template ?

enter image description here

The function which I have written on the page is just a sample one but the main priority is is resolve "Reference error: expect is not defined"

Any help on this would be really appreciated.

3

There are 3 answers

1
Icehorn On

If you are using a library (which it appears you are), you will need to import it in order to use the methods exported by it

0
Arun Ramachandran On

I managed to get it done by adding a CDN in the html section of the same JSBin. This method might be really helpful even if you can not find the required packages within the list of given packages

eg. <script src="http://cdnjs.cloudflare.com/ajax/libs/mocha/1.18.2/mocha.js"></script>

0
аlex On

Example of using expect in jest

https://jsbin.com/wapokahaxe/edit?html,console

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

</body>
</html>