DenoDDeno
Powered by
bennypB
Denoβ€’11mo agoβ€’
1 reply
bennyp

Using scopes in deno.json to mock modules for tests

Hello, I have something like this in my deno.json

  "imports": {
    "#css": "./src/css/documents.ts",
    "@std/assert": "jsr:@std/assert@1",
    "@std/collections": "jsr:@std/collections@^1.0.10",
    "@std/expect": "jsr:@std/expect@^1.0.15",
    "@std/io": "jsr:@std/io@^0.225.2",
    "@std/testing": "jsr:@std/testing@^1.0.11",
  },
  "scopes": {
    "./src/lsp/methods/textDocument/completion.test.ts": {
      "#css": "./test/css-mock.ts"
    }
  }
  "imports": {
    "#css": "./src/css/documents.ts",
    "@std/assert": "jsr:@std/assert@1",
    "@std/collections": "jsr:@std/collections@^1.0.10",
    "@std/expect": "jsr:@std/expect@^1.0.15",
    "@std/io": "jsr:@std/io@^0.225.2",
    "@std/testing": "jsr:@std/testing@^1.0.11",
  },
  "scopes": {
    "./src/lsp/methods/textDocument/completion.test.ts": {
      "#css": "./test/css-mock.ts"
    }
  }


completion.test.ts imports
completion.ts
completion.ts
which imports
#css
#css
.
I expect that when I run
deno test -A
deno test -A
, my mock module would be loaded, not the real one

instead the real one is loaded. Please advise how I can mock modules for testing.
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,944Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

how to use deno.json when using deno runtime in rust?
louis030195Llouis030195 / help
2y ago
deno.json for nextjs
GeaVerGGeaVer / help
17mo ago
How to debug tests in Deno on VSCODE
Alex Andru (@QuantGeekDev)AAlex Andru (@QuantGeekDev) / help
3y ago