Intenté usar broma para burlarme de la función importada pero recibí este error TypeError: Assignment to constant variable. o TypeError: Cannot assign to read only property 'sum' of object '[object Module]' , espero que obtuve el valor de retorno que me burlé en esta prueba
Intento 1
import { jest } from '@jest/globals' import * as util from "./util.js" it("TypeError: Cannot assign to read only property 'sum' of object '[object Module]'", () => { jest.spyOn(util, "sum").mockImplementation(() => { return 2 }) expect(sum(1, 2)).toBe(2); })Intento 2
import { jest } from '@jest/globals' import { sum } from './util.js' it("TypeError: Cannot assign to read only property 'sum' of object '[object Module]'", () => { jest.mock("./util.js", () => ({ __esModule: true, sum: jest.fn().mockReturnValue(2), })); expect(sum(1, 2)).toBe(2); })Intento 3
import { jest } from '@jest/globals' import { sum } from "./util.js" it("TypeError: Assignment to constant variable.", () => { sum = jest.fn(() => { return 2 }) expect(sum(1, 2)).toBe(2); })estoy siguiendo la documentación de broma https://jestjs.io/docs/ecmascript-modules para configurar mi configuración
paquete.json
{ "type": "module", "scripts": { "test": "NODE_OPTIONS=--experimental-vm-modules jest" }, }jest.config.js
module.exports = async () => { return { verbose: true, transform: {} }; };creé este repositorio para su reproducción https://github.com/fei1990a/jest-esm/tree/main
Gracias por cualquier ayuda