beeler
beeler
DDeno
Created by beeler on 4/16/2025 in #help
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 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 to prove its not only a type issue, but the type checker does catch it if you remove the --no-check flag. Is there anyway to get this example to work or another way to isolate 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
4 replies