mjackson / expect

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

expect.createSpy is not a function #244

Closed JairAviles closed 6 years ago

JairAviles commented 6 years ago

Env: cultofcoders:mocha + NodeJS 8.9.4 + npm@5.6.0 + expect@22.3.0

Working with a Meteor web app development I integrated the expect library (not using Jest) due to the fact that I am working with legacy code. Have defined in my React component file test as follows according to the README.md file

import expect, { createSpy } from 'expect';
...
        it('should call the function', function() {
            const spy = expect.createSpy();
            spy(3, 4, 123);
            expect(spy).toHaveBeenCalled();
        });

However, I am getting the following exception in the browser. What can I do to solve it? P.d. Not able to migrate to Jest for now because as I said, I am refactoring a legacy code that should be updated in the future but not for the moment.

TypeError: expect.createSpy is not a function
    at Context.<anonymous> (app/app.js?hash=02726a842e2206be159a89a48d59fc6bbf963a7b:500:24)
    at callFn (packages/practicalmeteor_mocha-core.js?hash=8beea7367d1e32321cbe94d562492c67d7ddc5d2:4359:21)
    at Test.Runnable.run (packages/practicalmeteor_mocha-core.js?hash=8beea7367d1e32321cbe94d562492c67d7ddc5d2:4352:7)
    at Runner.runTest (packages/practicalmeteor_mocha-core.js?hash=8beea7367d1e32321cbe94d562492c67d7ddc5d2:4822:10)
    at packages/practicalmeteor_mocha-core.js?hash=8beea7367d1e32321cbe94d562492c67d7ddc5d2:4933:12
    at next (packages/practicalmeteor_mocha-core.js?hash=8beea7367d1e32321cbe94d562492c67d7ddc5d2:4742:14)
    at packages/practicalmeteor_mocha-core.js?hash=8beea7367d1e32321cbe94d562492c67d7ddc5d2:4752:7
    at next (packages/practicalmeteor_mocha-core.js?hash=8beea7367d1e32321cbe94d562492c67d7ddc5d2:4684:14)
    at packages/practicalmeteor_mocha-core.js?hash=8beea7367d1e32321cbe94d562492c67d7ddc5d2:4720:5
    at timeslice (packages/practicalmeteor_mocha-core.js?hash=8beea7367d1e32321cbe94d562492c67d7ddc5d2:12688:27)
ljharb commented 6 years ago

expect v21+ is managed by jest; you’ll need to file the issue there.

JairAviles commented 6 years ago

Got it. At the end, I downgrade the expect library version to @1.20.2 and was able to continue with my spy definitions.