import LoadProfileScreenModule from '../Components/LoadProfileScreenModule' import 'react-native'; beforeEach(() => { fetch.resetMocks(); }); /** Testing the case when the username/login is not a person but other thing like an org */ test('expect throwing error', () => { fetch.mockResponseOnce(JSON.stringify({ "data": { "user": null }, "errors": [ { "type": "NOT_FOUND", "path": [ "user" ], "locations": [ { "line": 32, "column": 3 } ], "message": "Could not resolve to a User with the login of '???'." } ] })) const onResponse = jest.fn(); const onError = jest.fn(); const login = "???" const envData = require('C:/Coding/cs242-assignment3/env.json') const endPoint = envData['endPoint'] const token = envData['token'] const navigation = { push: jest.fn() }; return LoadProfileScreenModule(login, endPoint, token, navigation) .then(onResponse) .catch(onError) .finally(() => { // since in this situation, return value still contains data PKT thus still get in response state expect(onResponse).toHaveBeenCalled(); expect(onError).not.toHaveBeenCalled(); }); }, 70000); /** Testing the case when the Internet is down and loading Profile should return the error page and throw error*/ test('expect throwing error', () => { fetch.mockResponseOnce(JSON.stringify({ "data": { "user": null }, "errors": [ { "type": "INTERNET_DOWN", "path": [ "user" ], "locations": [ { "line": 32, "column": 3 } ], "message": "Cannot connect to graphQL API server." } ] })) const onResponse = jest.fn(); const onError = jest.fn(); const login = 'HenryShan' const envData = require('C:/Coding/cs242-assignment3/env.json') const endPoint = envData['endPoint'] const token = envData['token'] const navigation = { push: jest.fn() }; return LoadProfileScreenModule(login, endPoint, token, navigation) .then(onResponse) .catch(onError) .finally(() => { // since in this situation, return value still contains data PKT thus still get in response expect(onResponse).toHaveBeenCalled(); expect(onError).not.toHaveBeenCalled(); }); }, 70000);