Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

165
Vistas
Jest read published directory as if it published - SyntaxError Unexpected token ','

I have a library that I build and maintain. I'm trying to build a particular unit test with it. When I build a class around ClassWeProvide in TypeScript, the Jest unit tests work just fine.

I am trying to test a JS version since some of my library's users may want to use raw JavaScript. My Jest is in TS, and MyJSClass is in JS, intended to be using a "published" version of my library (dist/bundle.js) which is pre-built as part of my pipeline. (I webpack the library into a bundle.)

The issue I'm seeing is that the Jest file, on require is failing to load the JS file do to the require statement below. I cannot figure if I need to configure Jest, or do something entirely different, or maybe this isn't possible.

The library and ClassWeProvide are intended to be run in NodeJS, not the Frontend.

In jest.config.js:

module.exports = {
  testEnvironment: 'node',
  collectCoverage: false,
  coveragePathIgnorePatterns: ['dist', 'other', 'directories'],
  roots: ['<rootDir>'],
  transform: { '^.+\\.(t|j)s$': 'ts-jest' },
  transformIgnorePatterns: ['/node_modules/'],
  moduleFileExtensions: ['ts', 'js'],
  watchPathIgnorePatterns: ['node_modules'],
  moduleNameMapper: {
    'my-library': '<rootDir>'
  }
};

In my-class.js:

const { ClassWeProvide } = require('my-library');

module.exports = class MyJSClass extends ClassWeProvide {
  ...
};

In my MyJSClass.test.ts:

/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports */
const MyJSClass = require('../MyJSClass');

describe('My JS Class', () => {...});
SyntaxError: Unexpected token ','

> 1 | const { MyJSClass } = require('my-library');
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda