Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
Running unit test on JS runtime for es6 import statement

I am very new to NodeJS and JS as well. I have tried reading about resources like babel and rewire which help in resolving dependencies of ES6. But ended up being confused.

I am trying to write unit test for a JS runtime file which has import statements. The issue is that this file is a runtime file. This means that the import module only works when running in browser inside the dependent platform/application.

runtimeFile.js

import {something} from 'other-module'

function foo(){
}

export const toBeTested = {
    foo
}

unitTest.js

const toBeTested = require('./runtimeFile').toBeTested

describe('some test', () => {
    it('test a func', () => {
          const result = tobeTested.foo();
      });
});

When i try to run this unit test using mocha getting:

SyntaxError: Unexpected token {

This is for the import statement in runtimeFile.js.

So my question is around:

  1. How do i mock the import statement
  2. I am not sure what configuartion i need to do in order to get rid of this syntax error

I can provide more information as needed

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!