Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. const di: IDIContainer = configureTestDI();
  2. const knex = di.get<Knex>(APP_DEP.DB);
  3. const dbSeeder = di.get<DbSeeder>(APP_DEP.TEST_DB_SEEDER);
  4. const repo = new PostsRepo(knex);
  5.  
  6. describe("PostsRepo", () => {
  7. // to speed up our tests and do not trash test DB
  8. // we will run test in the transaction and roll it back after execution
  9. beforeEach(async () => {
  10. await knex.raw("BEGIN");
  11. });
  12. afterEach(async () => {
  13. await knex.raw("ROLLBACK");
  14. });
  15.  
  16. it("updates existing post", async () => {
  17. await dbSeeder.insert("post", { id: 12, title: "title1" });
  18.  
  19. repo.updatePost(12, { title: "title 2" });
  20.  
  21. const [updatedPost] = await knex("posts").where({ id: 12 });
  22. expect(updatedPost.title).toEqual("title 2");
  23. });
  24. });
  25. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement