Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

205
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda