Guest User

Untitled

a guest
May 23rd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. TypeError: Cannot read property 'fetch' of undefined
  2.  
  3. at node_modules/whatwg-fetch/fetch.js:4:11
  4. at Object.<anonymous> (node_modules/whatwg-fetch/fetch.js:461:3)
  5. at Object.<anonymous> (node_modules/jest-expo/src/setup.js:138:416)
  6.  
  7. "jest": {
  8. "preset": "jest-expo",
  9. "moduleFileExtensions": [
  10. "js",
  11. "jsx",
  12. "ts",
  13. "tsx"
  14. ],
  15. "verbose": true,
  16. "transform": {
  17. "^.+\.(js|ts|tsx)$": "<rootDir>/node_modules/babel-jest"
  18. },
  19. "testRegex": "(/__tests__/.*|\.(test|spec))\.(ts|tsx|js)$",
  20. "testPathIgnorePatterns": [
  21. "\.snap$",
  22. "<rootDir>/node_modules/",
  23. "<rootDir>/dist/"
  24. ],
  25. "transformIgnorePatterns": [
  26. "node_modules/?!react-native"
  27. ]
  28. },
  29.  
  30. const config = {
  31. entry: [
  32. 'whatwg-fetch',
  33. __dirname + '/src/index.ts',
  34. ],
  35. devtool: 'source-map',
  36. output: {
  37. path: path.join(__dirname, '/dist'),
  38. filename: 'index.js',
  39. library: 'checkinatwork-module',
  40. libraryTarget: 'umd',
  41. umdNamedDefine: true,
  42. },
  43. module: {
  44. loaders: [
  45. { test: /.(tsx|ts)?$/, loader: 'ts-loader', exclude: /node_modules/ },
  46. ],
  47. },
  48. resolve: {
  49. modules: [
  50. './src',
  51. 'node_modules',
  52. ],
  53. extensions: ['.js', '.ts', '.jsx', '.tsx', 'json'],
  54. },
  55. plugins: [
  56. ],
  57. };
  58.  
  59. import expect from 'expect';
  60. import * as actions from '../../src/components/Checkin/checkin.action';
  61. import * as reducers from '../../src/components/Checkin/checkin.reducer';
  62. import configureMockStore from 'redux-mock-store';
  63. import thunk from 'redux-thunk';
  64. import nock from 'nock';
  65.  
  66. const middlewares = [ thunk ];
  67. const mockStore = configureMockStore(middlewares);
  68.  
  69. describe('=> ADD CHECKIN ACTIONS', () => {
  70. describe('- REQUEST', () => {
  71. it('Action: ADD_CHECKIN_REQUEST should request addCawCheckin', () => {
  72. const expectedAction = {
  73. type: actions.ADD_CHECKIN_REQUEST,
  74. isFetching: true,
  75. };
  76. expect(actions.addCheckinRequest())
  77. .toEqual(expectedAction);
  78. });
  79. it('Reducer: newCheckin should trigger ADD_CHECKIN_REQUEST and initiate loading', () => {
  80. const expectedState = {
  81. isFetching: true,
  82. status: null,
  83. };
  84. expect(reducers.newCheckin(reducers.newCheckinDefaultState, actions.addCheckinRequest()))
  85. .toEqual(expectedState);
  86. });
  87. });
  88.  
  89. export const getCheckins = (sessionId, date, url, isRefresh) => {
  90. const config = {
  91. method: 'POST',
  92. headers: { 'Content-Type': 'application/json' },
  93. body: JSON.stringify({
  94. sessionId: {sessionId},
  95. date: {date},
  96. }),
  97. };
  98.  
  99. return dispatch => {
  100. if (!isRefresh) {
  101. dispatch(getCheckinsRequest());
  102. }
  103. return fetch(url + 'getCAWCheckIns', config)
  104. .then(response => response.json())
  105. .then(({ checkins }) => {
  106. dispatch(getCheckinsSuccess(checkins));
  107. }).catch(err => {
  108. dispatch(getCheckinsError('Get checkins failed'));
  109. console.error('Get checkins failed: ', err);
  110. });
  111. };
  112. };
  113.  
  114. import { fetch } from 'whatwg-fetch';
  115.  
  116. global.fetch = fetch;
  117.  
  118. __MOCKS__/globalMock.js
  119.  
  120. // use one of these imports
  121.  
  122. import { fetch } from 'whatwg-fetch' // if you want to keep using the polyfill
  123.  
  124. import { fetch } from 'isomorphic-fetch' // from a dependency node module that I spoke of in the previous solution.
  125.  
  126. global.fetch = fetch
  127.  
  128. "jest": {
  129. "verbose": true,
  130. "rootDir": "app",
  131. "setupFiles": ["<rootDir>/__MOCKS__/globalMock.js"]
  132. }
  133.  
  134. const { Response, Request, Headers, fetch } =
  135. require('fetch-everywhere');
  136. global.Response = Response;
  137. global.Request = Request;
  138. global.Headers = Headers;
  139. global.fetch = fetch;
Add Comment
Please, Sign In to add comment