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

Jest doesn't exit test cases automatically. #67

Open
Vijay-CodeAstu opened this issue Dec 18, 2018 · 5 comments
Open

Jest doesn't exit test cases automatically. #67

Vijay-CodeAstu opened this issue Dec 18, 2018 · 5 comments

Comments

@Vijay-CodeAstu
Copy link

Hey folks,

here's my configuration:

  "dependencies": {
    "sequelize": "^4.41.1",
    "sequelize-mock": "^0.10.2"
  }

Here is my test case:

const createData = require("../index.js");
const SequelizeMock = require("sequelize-mock");
const dbMock = new SequelizeMock();
const mockData = require('./mock');

describe("Create Data", () => {
  it("Should create data in sequelize", async done => {
    try {
      const result = await createData(mockData);

      expect(result).toBeDefined();
    } catch (err) {
      expect(err).toBeNull();
    }
  });
});

The test case passes, but jest console returns:
Jest did not exit one second after the test run has completed.

It might be something I missed from the tutorial.
Any pointers?

Let me know if I missed something above, I'll share it asap.

@Kareylo
Copy link

Kareylo commented Mar 11, 2019

Have you tried to call the done method ?

const createData = require("../index.js");
const SequelizeMock = require("sequelize-mock");
const dbMock = new SequelizeMock();
const mockData = require('./mock');

describe("Create Data", () => {
  it("Should create data in sequelize", async done => {
    try {
      const result = await createData(mockData);

      expect(result).toBeDefined();
    } catch (err) {
      expect(err).toBeNull();
    }
    done();
  });
});

@ghost
Copy link

ghost commented May 27, 2019

can you please what is in mockData?

@ghost
Copy link

ghost commented May 27, 2019

this is my test.js using jest
jest.mock('../models/cartype', () => () => {
const SequelizeMock = require("sequelize-mock");
const dbMock = new SequelizeMock();
return dbMock.define('cartype', {
cartypename: 'check1'
})
});

this is my sequelize model which i am trying to mock
'use strict';
module.exports = (sequelize, DataTypes) => {
const cartype = sequelize.define('cartype', {
cartypename: {
type: DataTypes.STRING,
allowNull: false,
},
}, {});
cartype.associate = function(models) {
// associations can be defined here
cartype.hasMany(models.car, {
foreignKey: 'cartypeid',
as: 'cartypeid',
});
};
return cartype;
};

here is my decribe of jest
describe("Test Sequelize Mocking", () => {
it("Should get value from mock", async () => {
const cartype = await cartypeController.list();
expect(cartype.cartypename).toEqual('check1');
})
})

i am getting error as below while mocking with sequelize-mock

NODE_ENV=test jest

FAIL server/test/function.test.js
● Test suite failed to run

car.belongsTo called with something that's not a subclass of Sequelize.Model

  32 |       onDelete: 'CASCADE',
  33 |     }),
> 34 |     car.belongsTo(models.cartype, {
     |         ^
  35 |       foreignKey: 'cartypeid',
  36 |       onDelete: 'CASCADE',
  37 |     }),

  at Function.<anonymous> (node_modules/sequelize/lib/associations/mixin.js:93:13)
  at Function.belongsTo (server/models/car.js:34:9)
  at associate (server/models/index.js:30:19)
      at Array.forEach (<anonymous>)
  at Object.forEach (server/models/index.js:28:17)
  at Object.require (server/controllers/cartypeController.js:1:17)
  at Object.require (server/test/function.test.js:2:27)

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 8.89s
Ran all test suites.
Note: This command was run via npm module 'win-node-env'
npm ERR! Test failed. See above for more details.

anyone able to help please do
Thanks in advance

@aadi009
Copy link

aadi009 commented Jul 29, 2019

I am also getting the same type of error.

@anthony-baru
Copy link

You will have to jest.mock you car model the same way you did cartype 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

4 participants