Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import * as chai from "chai";
  2. import * as td from "testdouble";
  3. import * as typeorm from "typeorm";
  4.  
  5. const sinon = require("sinon");
  6. const sinonChai = require("sinon-chai");
  7.  
  8. chai.use(sinonChai);
  9.  
  10. declare global {
  11. namespace NodeJS {
  12. interface Global {
  13. td: any;
  14. chai: any;
  15. spy: any;
  16. sinon: any;
  17. }
  18. }
  19. }
  20.  
  21. global.td = td;
  22. global.chai = chai;
  23. global.spy = sinon.spy;
  24.  
  25. const sandbox = sinon.createSandbox();
  26. const connection = sinon.createStubInstance(typeorm.Connection, {
  27. findMetadata() {
  28. return {};
  29. },
  30. buildMetadatas() {
  31. return {};
  32. }
  33. });
  34. let manager;
  35. connection.transaction.callsFake(async fn => fn(manager)); // eslint-disable-line
  36. sinon.stub(typeorm, "getConnection").returns(connection);
  37.  
  38. beforeEach(() => {
  39. manager = sandbox.createStubInstance(typeorm.EntityManager);
  40. });
  41.  
  42. afterEach(() => sandbox.restore());
  43.  
  44. console.log("bootstrap code here");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement