Skip to content

“findOne is not a function” with jest #9

Description

@acidos

I am using sequelize mock v5 to mock User model.

// user.test.js
import User from "../models/user"; // original user model class

jest.mock("../models/user", () => () => {
    const SequelizeMock = require("sequelize-mock-v5");
    const dbMock = new SequelizeMock();
    return dbMock.define("User", { id: 111, username: "myusername" });
});

test("blabla", async () => {
    const r = await User.findOne({ where: { id:1 }});
    // expectations here
});

This gives me

TypeError: _user.default.findOne is not a function

Here is the original User model which I am trying to mock.

// /models/user.js
export default class User extends Model {...}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions