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
[QUESTION] Integration with Jest - Schema hasn't been registered for model #793
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 |
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
The text was updated successfully, but these errors were encountered: