brash-appointment-91676
05/26/2023, 3:25 PMts
export const testConstant = "initial"
test file:
ts
import * as testExports from "./index.ts";
it("changes the module", () => {
cy.stub(testExports, "testConstant")
.value("VALUE")
expect(testExports.testConstant).to.eq("VALUE")
})
Result:
js
TypeError: Cannot redefine property: testConstant
at Function.defineProperty (<anonymous>)
at Object.value (/__cypress/runner/cy…runner.js:129024:16)
at proto.<computed> [as value] (/__cypress/runner/cy…runner.js:128601:12)
at Function.<anonymous> (/__cypress/runner/cy…runner.js:128594:46)
at runnable.fn (/__cypress/runner/cy…runner.js:160854:19)
at callFn (/__cypress/runner/cy…runner.js:114387:21)
at ../driver/node_modules/mocha/lib/runnable.js.Runnable.run (/__cypress/runner/cy…_runner.js:114374:7)
at <unknown> (/__cypress/runner/cy…runner.js:167842:30)
at PassThroughHandlerContext.finallyHandler (/__cypress/runner/cy…_runner.js:15298:23)
at PassThroughHandlerContext.tryCatcher (/__cypress/runner/cy…_runner.js:18744:23)
at Promise._settlePromiseFromHandler (/__cypress/runner/cy…_runner.js:16679:31)
at Promise._settlePromise (/__cypress/runner/cy…_runner.js:16736:18)
at Promise._settlePromise0 (/__cypress/runner/cy…_runner.js:16781:10)
at Promise._settlePromises (/__cypress/runner/cy…_runner.js:16861:18)
at Promise._fulfill (/__cypress/runner/cy…_runner.js:16805:18)
at Promise._settlePromise (/__cypress/runner/cy…_runner.js:16749:21)
at Promise._settlePromise0 (/__cypress/runner/cy…_runner.js:16781:10)
at Promise._settlePromises (/__cypress/runner/cy…_runner.js:16861:18)
at Promise._fulfill (/__cypress/runner/cy…_runner.js:16805:18)
at Promise._resolveCallback (/__cypress/runner/cy…_runner.js:16599:57)
at Promise._settlePromiseFromHandler (/__cypress/runner/cy…_runner.js:16691:17)
brash-appointment-91676
05/26/2023, 3:42 PMgray-kilobyte-89541
05/26/2023, 3:47 PMbrash-appointment-91676
05/26/2023, 4:02 PMbrash-appointment-91676
05/26/2023, 4:09 PMts
vi.mock("path", () => ({
default: "value"
}))
Is this possible with Cypress?brash-appointment-91676
05/26/2023, 4:23 PMgray-kilobyte-89541
05/26/2023, 4:29 PMhttps://cdn.discordapp.com/attachments/1111676475192639610/1111692496418918500/Screenshot_2023-05-26_at_12.28.44.png▾
brash-appointment-91676
05/26/2023, 4:30 PMbrash-appointment-91676
05/26/2023, 4:32 PMbrash-appointment-91676
05/26/2023, 4:50 PM