react-native-google-signin defines the following:
export interface GoogleSigninButtonProps extends ViewProps {
style?: StyleProp<ViewStyle>;
size?: GoogleSigninButton.Size;
color?: GoogleSigninButton.Color;
disabled?: boolean;
onPress?(): void;
}
export class GoogleSigninButton extends React.Component<GoogleSigninButtonProps> {
constructor(props: GoogleSigninButtonProps);
}
export namespace GoogleSigninButton {
enum Size {
Standard,
Wide,
Icon,
}
enum Color {
Light,
Dark,
}
}
and in my code I am using it as such:
<GoogleSigninButton
style={{ width: 192, height: 48 }}
size={GoogleSigninButton.Size.Wide}
color={GoogleSigninButton.Color.Dark}
onPress={this.authenticate}
testID={'GoogleAuthenticationButton'}
/>
I have written my test to try an mock this as follows:
jest.mock('react-native-google-signin', () => ({
GoogleSigninButton: {
Size: {
Standard: 0,
Wide: 1,
Icon: 2
},
Color: {
Light: 0,
Dark: 1
}
}
}))
However I get the following error:
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
I have tried setting the GoogleSigninButton: 'GoogleSigninButton' and that will fix the expected return type but it will generate other errors such as Size and Color being undefined. If I keep it as is, then I get the error above.
How can I mock the above class so that it will return a string for GoogleSignInButton but also define the Size and Color properties so it doesn't throw a 'Cannot read property Size of undefined'?