Guest User

Untitled

a guest
Jan 16th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. 'use strict';
  2.  
  3. var mockDelay;
  4. var mockError;
  5. var mockResponse = {
  6. status: function () {
  7. return 200;
  8. },
  9. ok: true,
  10. get: jest.genMockFunction(),
  11. toError: jest.genMockFunction()
  12. };
  13.  
  14. var Request = {
  15. post: jest.genMockFunction().mockReturnThis(),
  16. get: jest.genMockFunction().mockReturnThis(),
  17. send: jest.genMockFunction().mockReturnThis(),
  18. query: jest.genMockFunction().mockReturnThis(),
  19. field: jest.genMockFunction().mockReturnThis(),
  20. set: jest.genMockFunction().mockReturnThis(),
  21. accept: jest.genMockFunction().mockReturnThis(),
  22. timeout: jest.genMockFunction().mockReturnThis(),
  23. end: jest.genMockFunction().mockImplementation(function (callback) {
  24. if (mockDelay) {
  25. this.delayTimer = setTimeout(callback, 0, mockError, mockResponse);
  26.  
  27. return;
  28. }
  29.  
  30. callback(mockError, mockResponse);
  31. }),
  32.  
  33. __setMockDelay: function (boolValue) {
  34. mockDelay = boolValue;
  35. },
  36. __setMockResponse: function (mockRes) {
  37. mockResponse = mockRes;
  38. },
  39. __setMockError: function (mockErr) {
  40. mockError = mockErr;
  41. },
  42. __setMockResponseBody: function (body) {
  43. mockResponse.body = body;
  44. }
  45. };
  46.  
  47. module.exports = Request;
Add Comment
Please, Sign In to add comment