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

267
Vistas
How to disable "Use Strict" in Jest

I am writing some unit tests for a codebase which uses octal literals. Whenever the test is executed with npm test, a syntax error appears as follows:

Legacy octal literals are not allowed in strict mode.

I should stress that "use strict" does not appear anywhere in the source code, nor can I identify any option in package-lock.json or package.json indicating strict mode. Both JSON files were created with the npm init -y and received no further modification except the addition of:

  "scripts": {
    "test": "jest"
  },

How can I force Jest out of strict mode in order to test code with legacy octal literals?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Per the docs:

By default, Jest will use babel-jest transformer

You can explicitly tell Jest you don't want it to try to apply any transforms by setting the following Jest configuration (e.g. in jest.config.<ext> or under $.jest in the package file):

"transform": {}

See full example below. Alternatively, you can leave Babel's transforms active but configure it with "sourceType": "script".


  • package.json:

    {
      "name": "strict-jest",
      "version": "0.1.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "test": "jest"
      },
      "keywords": [],
      "author": "",
      "license": "ISC",
      "devDependencies": {
        "jest": "^28.1.2"
      },
      "jest": {
        "transform": {}
      }
    }
    
  • index.test.js:

    it("works", () => {
      expect(0100).toEqual(64);
    });
    
  • Output:

    $ npm t
    
    > strict-jest@0.1.0 test
    > jest
    
     PASS  ./index.test.js
      ✓ works (2 ms)
    
    Test Suites: 1 passed, 1 total
    Tests:       1 passed, 1 total
    Snapshots:   0 total
    Time:        0.257 s
    Ran all test suites.
    
about 4 years ago · Juan Pablo Isaza Denunciar
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