Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TypeError: Cannot read property 'fetch' of undefined
- at node_modules/whatwg-fetch/fetch.js:4:11
- at Object.<anonymous> (node_modules/whatwg-fetch/fetch.js:461:3)
- at Object.<anonymous> (node_modules/jest-expo/src/setup.js:138:416)
- "jest": {
- "preset": "jest-expo",
- "moduleFileExtensions": [
- "js",
- "jsx",
- "ts",
- "tsx"
- ],
- "verbose": true,
- "transform": {
- "^.+\.(js|ts|tsx)$": "<rootDir>/node_modules/babel-jest"
- },
- "testRegex": "(/__tests__/.*|\.(test|spec))\.(ts|tsx|js)$",
- "testPathIgnorePatterns": [
- "\.snap$",
- "<rootDir>/node_modules/",
- "<rootDir>/dist/"
- ],
- "transformIgnorePatterns": [
- "node_modules/?!react-native"
- ]
- },
- const config = {
- entry: [
- 'whatwg-fetch',
- __dirname + '/src/index.ts',
- ],
- devtool: 'source-map',
- output: {
- path: path.join(__dirname, '/dist'),
- filename: 'index.js',
- library: 'checkinatwork-module',
- libraryTarget: 'umd',
- umdNamedDefine: true,
- },
- module: {
- loaders: [
- { test: /.(tsx|ts)?$/, loader: 'ts-loader', exclude: /node_modules/ },
- ],
- },
- resolve: {
- modules: [
- './src',
- 'node_modules',
- ],
- extensions: ['.js', '.ts', '.jsx', '.tsx', 'json'],
- },
- plugins: [
- ],
- };
- import expect from 'expect';
- import * as actions from '../../src/components/Checkin/checkin.action';
- import * as reducers from '../../src/components/Checkin/checkin.reducer';
- import configureMockStore from 'redux-mock-store';
- import thunk from 'redux-thunk';
- import nock from 'nock';
- const middlewares = [ thunk ];
- const mockStore = configureMockStore(middlewares);
- describe('=> ADD CHECKIN ACTIONS', () => {
- describe('- REQUEST', () => {
- it('Action: ADD_CHECKIN_REQUEST should request addCawCheckin', () => {
- const expectedAction = {
- type: actions.ADD_CHECKIN_REQUEST,
- isFetching: true,
- };
- expect(actions.addCheckinRequest())
- .toEqual(expectedAction);
- });
- it('Reducer: newCheckin should trigger ADD_CHECKIN_REQUEST and initiate loading', () => {
- const expectedState = {
- isFetching: true,
- status: null,
- };
- expect(reducers.newCheckin(reducers.newCheckinDefaultState, actions.addCheckinRequest()))
- .toEqual(expectedState);
- });
- });
- export const getCheckins = (sessionId, date, url, isRefresh) => {
- const config = {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({
- sessionId: {sessionId},
- date: {date},
- }),
- };
- return dispatch => {
- if (!isRefresh) {
- dispatch(getCheckinsRequest());
- }
- return fetch(url + 'getCAWCheckIns', config)
- .then(response => response.json())
- .then(({ checkins }) => {
- dispatch(getCheckinsSuccess(checkins));
- }).catch(err => {
- dispatch(getCheckinsError('Get checkins failed'));
- console.error('Get checkins failed: ', err);
- });
- };
- };
- import { fetch } from 'whatwg-fetch';
- global.fetch = fetch;
- __MOCKS__/globalMock.js
- // use one of these imports
- import { fetch } from 'whatwg-fetch' // if you want to keep using the polyfill
- import { fetch } from 'isomorphic-fetch' // from a dependency node module that I spoke of in the previous solution.
- global.fetch = fetch
- "jest": {
- "verbose": true,
- "rootDir": "app",
- "setupFiles": ["<rootDir>/__MOCKS__/globalMock.js"]
- }
- const { Response, Request, Headers, fetch } =
- require('fetch-everywhere');
- global.Response = Response;
- global.Request = Request;
- global.Headers = Headers;
- global.fetch = fetch;
Add Comment
Please, Sign In to add comment