5

I'm guessing it's an import error somehow, but I can't seem to figure out how, expect is up to date and I can't get it too run without it saying

libarary TypeError: expect(...).toInclude is not a function

var request = require("supertest");
var {app} = require("./../server.js");
var {Show} = require("./../models/show");
var expect = require('expect');

    describe("GET /show/:id", () => {
        it("Should include the show name 'Arrow' in the body", (done) => {
            request(app)
            .get(`/show/${showName}`)
            .expect(200)
            .expect((res) => {
                expect('hello world').toInclude('world')

            })
            .end(done);
        });
    })

});
meuh
  • 11,500
  • 2
  • 29
  • 45
  • one of it's alias's works for me "toContain", I don't know if toInclude is not in the module anymore, if you know please let me know –  Mar 08 '18 at 20:33
  • The answer here: https://stackoverflow.com/a/46459995/1424833 may help. – Matt Holland Mar 08 '18 at 21:35
  • @MattHolland I guess that's it, I don't see the method toInclude in there, thanks for sharing that. If you would want to post the answer referencing that API and i'll accept it –  Mar 08 '18 at 22:28

3 Answers3

10

UPDATE: besides .toMatchObject, you can also use .toHaveProperty


For anyone who used .toInclude to check if an object contains certain fields, the new version is .toMatchObject.

Here is the document reference

MaXon
  • 465
  • 2
  • 8
  • 17
2

The expect library was recently made part of the Jest project - the Jest team changed the API a little, as this answer explains.

The full documentation for expect can now be found here: https://facebook.github.io/jest/docs/en/expect.html

Matt Holland
  • 2,190
  • 3
  • 22
  • 26
0

If you are facing similar problem than it can be solved by importing jest-dom in your test file: import '@testing-library/jest-dom' in your xyz.test.js

Don't forget to install jest-dom in order to use it with jest:

npm i --save-dev @testing-library/jest-dom

Hope it helps.. :)

Victor S.
  • 2,510
  • 3
  • 22
  • 35