Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. import { getReposByUsername as action } from "./repos";
  2. import {
  3. REPOS_SUCCESS,
  4. REPOS_EMPTY,
  5. REPOS_NOT_FOUND,
  6. REPOS_ERROR
  7. } from "../constants/ActionTypes";
  8.  
  9. describe("repos action", () => {
  10. const username = "user";
  11. const mockDispatch = jest.fn();
  12. const mockService = {};
  13.  
  14. beforeEach(() => {
  15. mockDispatch.mockReset();
  16. });
  17.  
  18. it("should handle the success case", async () => {
  19. mockService.getResposByUserName = () => ({
  20. data: ["some data"]
  21. });
  22.  
  23. await action(mockDispatch, mockService, username);
  24. expect(mockDispatch).toHaveBeenCalledTimes(2);
  25. expect(mockDispatch).toHaveBeenLastCalledWith({
  26. type: REPOS_SUCCESS,
  27. repos: ["some data"]
  28. });
  29. });
  30.  
  31. it("should handle the empty case", async () => {
  32. mockService.getResposByUserName = () => ({
  33. data: []
  34. });
  35. await action(mockDispatch, mockService, username);
  36. expect(mockDispatch).toHaveBeenCalledTimes(2);
  37. expect(mockDispatch).toHaveBeenLastCalledWith({
  38. type: REPOS_EMPTY
  39. });
  40. });
  41.  
  42. it("should handle the 404 case", async () => {
  43. mockService.getResposByUserName = () => {
  44. throw { response: { status: 404 } };
  45. };
  46. await action(mockDispatch, mockService, username);
  47. expect(mockDispatch).toHaveBeenCalledTimes(2);
  48. expect(mockDispatch).toHaveBeenLastCalledWith({
  49. type: REPOS_NOT_FOUND
  50. });
  51. });
  52.  
  53. it("should handle the connection error", async () => {
  54. mockService.getResposByUserName = () => {
  55. throw {};
  56. };
  57. await action(mockDispatch, mockService, username);
  58. expect(mockDispatch).toHaveBeenCalledTimes(2);
  59. expect(mockDispatch).toHaveBeenLastCalledWith({
  60. type: REPOS_ERROR
  61. });
  62. });
  63. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement