Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

“findOne is not a function” with jest #9

Open
acidos opened this issue Jun 1, 2021 · 0 comments
Open

“findOne is not a function” with jest #9

acidos opened this issue Jun 1, 2021 · 0 comments

Comments

@acidos
Copy link

acidos commented Jun 1, 2021

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 {...}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant