mjackson / expect

Write better assertions
MIT License
2.29k stars 117 forks source link

“test is not defined” jest/expect on client side #250

Closed IndusFireTiger closed 6 years ago

IndusFireTiger commented 6 years ago

I get "test is not defined" Uncaught ReferenceError on the browser.

I dont use ESLINT, which according to this linkis the solution to "test is not defined". "test" which is a global in jest/expect testing library, it is expected to be available after the including the expect.min.js file in the test.html

In that case what could be the other reasons and their solution.

here is my code:

<script src='script.js'></script>
<script>
  test('myTest', () => {
    a = {}
    b = {}
    a.rating = 1
    b.rating = 2
    expect(sortAlgo(a,b)).toBe(1)
  })

ljharb commented 6 years ago

What version of expect are you using? That looks like v21 - v21+ of expect is a different project maintained by the jest team, per the readme: https://github.com/mjackson/expect#notice

IndusFireTiger commented 6 years ago

As suggested in the https://github.com/mjackson/expect#installation, I am using this link

So according to you 'test' is not available on expect older version. But according to Jest official docs https://jestjs.io/docs/en/expect#reference 'test' is a global. This could mean that test is available only on the higher versions of expect.

If so can you suggest the library link to the version where I can use 'expect' along with 'test'.

ljharb commented 6 years ago

Yes, it’s in the read me which i linked. Please read it :-)