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?
Per the docs:
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$.jestin the package file):See full example below. Alternatively, you can leave Babel's transforms active but configure it with
"sourceType": "script".package.json:index.test.js:Output: