DenoDDeno
Powered by
beelerB
Denoβ€’11mo agoβ€’
3 replies
beeler

Basic Mocking example for `override global or imported objects` does not work

I am following the example https://docs.deno.com/examples/testing_tutorial/#basic-mocking and when run with
deno test --no-check
deno test --no-check
the example fails with:

getUserDetails formats the name correctly => ./service_test.ts:5:6
error: TypeError: Cannot assign to read only property 'getUserFromDB' of object '[object Module]'
  db.getUserFromDB = async (id: string) => {
                  ^
    at file:///home/.../service_test.ts:10:19
getUserDetails formats the name correctly => ./service_test.ts:5:6
error: TypeError: Cannot assign to read only property 'getUserFromDB' of object '[object Module]'
  db.getUserFromDB = async (id: string) => {
                  ^
    at file:///home/.../service_test.ts:10:19


I'm running with
--no-checks
--no-checks
to prove its not only a type issue, but the type checker does catch it if you remove the
--no-check
--no-check
flag.

Is there anyway to get this example to work or another way to isolate
imports
imports
in Deno?

I am using the latest Deno:

$ deno --version
deno 2.2.10 (stable, release, x86_64-unknown-linux-gnu)
v8 13.5.212.10-rusty
typescript 5.7.3
$ deno --version
deno 2.2.10 (stable, release, x86_64-unknown-linux-gnu)
v8 13.5.212.10-rusty
typescript 5.7.3
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,934Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Incorrect documentation example (partial mocking)
Jess182JJess182 / help
10mo ago
ES Module mocking workaround
SMellSSMell / help
3y ago
Basic react server side rendering does not work on Deno Deploy but does locally
didiercrunchDdidiercrunch / help
3y ago