Skip to content

Instantly share code, notes, and snippets.

@radzserg
Last active October 4, 2019 15:34
Show Gist options
  • Select an option

  • Save radzserg/0326d77347f6685d9aa113da13fb3b7f to your computer and use it in GitHub Desktop.

Select an option

Save radzserg/0326d77347f6685d9aa113da13fb3b7f to your computer and use it in GitHub Desktop.
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");
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment