alert-shampoo-49789
09/11/2023, 3:04 PMyarn test with Jest
node_modules/@rudderstack/rudder-sdk-react-native/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { NativeModules, Platform } from 'react-native';
^^^^^^
SyntaxError: Cannot use import statement outside a module
import rudderClient from '@rudderstack/rudder-sdk-react-native'
Has this been raised as an issue previously? I’ve tried a few solutions, but nothing seems to solve this for me currently.
Thanksmillions-activity-52391
09/11/2023, 3:04 PMmillions-activity-52391
09/11/2023, 3:44 PMkind-carpenter-27609
09/11/2023, 3:53 PMalert-shampoo-49789
09/11/2023, 4:56 PMcalm-yak-10773
09/11/2023, 5:10 PMalert-shampoo-49789
09/11/2023, 5:11 PMcalm-yak-10773
09/11/2023, 5:42 PMalert-shampoo-49789
09/12/2023, 1:32 PMbabel.config.js, but I’m still seeing those same errors.alert-shampoo-49789
09/12/2023, 1:32 PMcalm-yak-10773
09/12/2023, 2:34 PMWould it have anything to do with needing to mock Rudderstack for Jest?I don’t think so. Did you tried this steps as well:
Also consider adding this:Copy codenpm install --save-dev @babel/core @babel/preset-env
As per my understanding this is a babel/jest configuration issue. I’m trying to reproduce this issue at my end but currently unable to. Hence, it would be helpful, if you consider sharing a minimal reproducible example.Copy codepresets: ['@babel/preset-env', '@babel/preset-react'],
alert-shampoo-49789
09/12/2023, 4:13 PMcalm-yak-10773
09/12/2023, 4:17 PMcalm-yak-10773
09/12/2023, 5:25 PMWould it have anything to do with needing to mock Rudderstack for Jest?It worked and solved the issue. Please add this line in your test file to solve this issue:
jest.mock("@rudderstack/rudder-sdk-react-native", () => jest.fn());
Please LMK if it works or not.alert-shampoo-49789
09/12/2023, 5:26 PMalert-shampoo-49789
09/12/2023, 5:26 PM