Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const di: IDIContainer = configureTestDI();
- const knex = di.get<Knex>(APP_DEP.DB);
- const dbSeeder = di.get<DbSeeder>(APP_DEP.TEST_DB_SEEDER);
- const repo = new PostsRepo(knex);
- describe("PostsRepo", () => {
- // to speed up our tests and do not trash test DB
- // we will run test in the transaction and roll it back after execution
- beforeEach(async () => {
- await knex.raw("BEGIN");
- });
- afterEach(async () => {
- await knex.raw("ROLLBACK");
- });
- it("updates existing post", async () => {
- await dbSeeder.insert("post", { id: 12, title: "title1" });
- repo.updatePost(12, { title: "title 2" });
- const [updatedPost] = await knex("posts").where({ id: 12 });
- expect(updatedPost.title).toEqual("title 2");
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement