Skip to content

Commit

Permalink
[home] Fix Home unit tests
Browse files Browse the repository at this point in the history
ExponentKernel now defines some methods and is part of our auto-generated jest-expo mocks, so the way we need to mock it in Home tests has changed slightly.

Test plan: `yarn test` in home
  • Loading branch information
ide committed Nov 9, 2018
1 parent 5fb2f15 commit e52cb9e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions home/api/ApiV2HttpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export default class ApiV2HttpClient {
let fetchOptions: any = {
method: options.httpMethod,
headers: {
'Exponent-SDK-Version': ExponentKernel.sdkVersions,
'Exponent-Platform': Platform.OS,
'Expo-SDK-Version': ExponentKernel.sdkVersions,
'Expo-Platform': Platform.OS,
},
};
if (options.body) {
Expand Down
10 changes: 4 additions & 6 deletions home/api/__tests__/ApiV2HttpClient-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import ApiV2Error from '../ApiV2Error';

jest.mock('react-native', () => {
const ReactNative = require.requireActual('react-native');
ReactNative.NativeModules.ExponentKernel = {
sdkVersions: '12.0.0,11.0.0',
};
ReactNative.NativeModules.ExponentKernel.sdkVersions = '12.0.0,11.0.0';
return ReactNative;
});

Expand Down Expand Up @@ -66,15 +64,15 @@ it(`supports slashes in method names`, async () => {
expect(global.fetch.mock.calls[0][0]).toMatch(/\/api\/v2\/prefix\/method$/);
});

it(`sets custom Exponent headers`, async () => {
it(`sets custom Expo headers`, async () => {
_setFakeHttpResponse('{"data": {"test":"yes"}}');

let client = new ApiV2HttpClient();
await client.getAsync('example');

let headers = global.fetch.mock.calls[0][1].headers;
expect(headers['Exponent-SDK-Version']).toBe('12.0.0,11.0.0');
expect(headers['Exponent-Platform']).toBe('ios');
expect(headers['Expo-SDK-Version']).toBe('12.0.0,11.0.0');
expect(headers['Expo-Platform']).toBe('ios');
});

it(`handles API errors`, async () => {
Expand Down

0 comments on commit e52cb9e

Please sign in to comment.