Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: jest setup was voiding custom turbo mocks #636

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions __tests__/banner.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import * as ReactNative from 'react-native';
import React from 'react';
import { render } from '@testing-library/react-native';
import { BannerAd, BannerAdSize } from '../src';

const MOCK_ID = 'MOCK_ID';

jest.doMock('react-native', () => {
return Object.setPrototypeOf(
{
...ReactNative,
Platform: {
OS: 'android',
select: () => {},
},
},
ReactNative,
);
});

describe('Google Mobile Ads Banner', function () {
it('throws if no unit ID was provided.', function () {
let errorMsg;
Expand Down
3 changes: 2 additions & 1 deletion docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
["European User Consent", "/european-user-consent"],
["Ad Inspector", "/ad-inspector"],
["Impression-level ad revenue", "/impression-level-ad-revenue"],
["Video ad volume control", "/video-ad_volume-control"]
["Video ad volume control", "/video-ad_volume-control"],
["Testing", "/testing"]
]
],
[
Expand Down
17 changes: 17 additions & 0 deletions docs/testing.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Testing

The React Native Google Mobile Ads library depends on a lot of platform-specific native code which you likely want to mock in your tests.

## Testing with Jest

This library ships with a Jest setup file that mocks the native code for you.
To use it, add the following to your Jest configuration:

```json
// jest.config.js|ts|mjs|cjs|json
{
"setupFiles": [
"./node_modules/react-native-google-mobile-ads/jest.setup.ts"
]
}
```
5 changes: 1 addition & 4 deletions jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import * as ReactNative from 'react-native';
jest.doMock('react-native', () => {
return Object.setPrototypeOf(
{
Platform: {
OS: 'android',
select: () => {},
},
NativeModules: {
...ReactNative.NativeModules,
RNAppModule: {
Expand All @@ -28,6 +24,7 @@ jest.doMock('react-native', () => {
RNGoogleMobileAdsConsentModule: {},
},
TurboModuleRegistry: {
...ReactNative.TurboModuleRegistry,
getEnforcing: () => {
return {
initialize: jest.fn(),
Expand Down
Loading