bennyp
bennyp5d ago

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 which imports #css. I expect that when I run 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.
1 Reply
bennyp
bennypOP3d ago
I solved this by passing context param into my functions - more testable that way

Did you find this page helpful?