Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up[QUESTION] Integration with Jest - Schema hasn't been registered for model #793
Labels
Comments
|
Hello @gustavovendramini It should solve your problem :) See you |
|
@Romakita That not worked for me ... But I followed @striquer tip and it worked
|
|
Ha ook :) import {TestMongooseContext} from "@tsed/testing-mongoose";
import { MongooseModel } from "@tsed/mongoose";
import { Spirit } from '../src/models/Spirit';
describe("SpiritModel", () => {
beforeEach(TestMongooseContext.create);
afterEach(TestMongooseContext.reset);
it("get a wild spirit", TestMongooseContext.inject([SpiritModel], async (model: MongooseModel<SpiritModel>) => {
// GIVEN - Create and add data to the mocked database
const spirit = new SpiritModel({ wild: true, power: 1, state: '' });
await user.save();
// THEN - Get the data in the mocked database
const result = await SpiritModel.findOne({ wild: true, power: 1, state: '' }).exec();
expect(result?.wild).toBe(true);
}));
});I think when you have tested the solution given document, you've missed to populate the mocked database befare run the findOne() method :) See you |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to load Ts.ED schemas outside the server context?
I'm writing tests with Jest and I`m receiving this:
I have tried with
const SpiritModel = mongoose.model('Spirit') as MongooseModel<Spirit>but no sucess.I'm using Typescript 3.8.3, Ts.ED 5.44, Jest/ts-jest 25.x and express 4.17
mytest.test.ts
package.json
jest.config.js