Skip to content

Commit

Permalink
add mock
Browse files Browse the repository at this point in the history
  • Loading branch information
vonovak committed Aug 22, 2018
1 parent 4bda9b0 commit 8a8d540
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ Read [iOS documentation](https://developers.google.com/identity/sign-in/ios/back

Read [iOS documentation](https://developers.google.com/identity/sign-in/ios/offline-access) and [Android documentation](https://developers.google.com/identity/sign-in/android/offline-access) for more information

## Jest module mock

If you use Jest for testing, you may need to mock the functionality of this native module. This library ships with a Jest mock that you can add to the `setupFiles` array in the Jest config. By default, it behaves as if the calls were successful and returns mock user data.

```
"setupFiles": [
"./node_modules/react-native-google-signin/jest/RNGoogleSigninMock.js"
],
```

## Additional scopes

The default requested scopes are `email` and `profile`.
Expand Down
26 changes: 26 additions & 0 deletions jest/RNGoogleSigninMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const mockUserInfo = {
idToken: 'mockIdToken',
accessToken: null,
accessTokenExpirationDate: null, // DEPRECATED, on iOS it's a time interval since now in seconds, on Android it's always null
serverAuthCode: 'mockServerAuthCode',
scopes: [], // on iOS this is empty array if no additional scopes are defined
user: {
email: 'mockEmail',
id: 'mockId',
givenName: 'mockGivenName',
familyName: 'mockFamilyName',
photo: 'mockPhotoUtl',
name: 'mockFullName',
},
};

jest.mock('react-native-google-signin', () => ({
GoogleSignin: {
configure: jest.fn(),
hasPlayServices: jest.fn(() => Promise.resolve(true)),
signIn: jest.fn(() => Promise.resolve(mockUserInfo)),
signInSilently: jest.fn(() => Promise.resolve(mockUserInfo)),
revokeAccess: jest.fn(() => Promise.resolve(true)),
signOut: jest.fn(() => Promise.resolve(true)),
},
}));

0 comments on commit 8a8d540

Please sign in to comment.