Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting up Jasmine + Webdriver - "cannot use import outside a module"

I'm trying to set up a basic automated test in the browser against a react app, using webdriver and Jasmine. I'm using page object models to describe my app under test, like so:

Example page object from JasmineBDD

I'm running Jasmine fine, and slurping up the spec. However after the browser spawns, I get a module error

import { SplashScreen } from './page_models/splash_screen.page'
^^^^^^

SyntaxError: Cannot use import statement outside a module

I'm initiating the test with a local call to wdio, node node_modules/.bin/wdio ./spec/support/wdio.conf.js . How do I run my Jasmine spec code in an environment so that it's inside a module context ?

Thanks :)

like image 732
ether_joe Avatar asked Dec 25 '19 03:12

ether_joe


Video Answer


1 Answers

Turns out I needed to call babel/register in my jasmine config like so:

   beforeSession: function (config, capabilities, specs) {
      require('@babel/register');
    },
like image 59
ether_joe Avatar answered Sep 23 '22 09:09

ether_joe