kt3k
kt3k
DDeno
Created by Jess182 on 5/23/2025 in #help
Incorrect documentation example (partial mocking)
I'm trying to fix the docs above https://github.com/denoland/docs/pull/1766
9 replies
DDeno
Created by Jess182 on 5/23/2025 in #help
Incorrect documentation example (partial mocking)
See also the docs in JSR https://jsr.io/@std/testing/doc/mock
9 replies
DDeno
Created by Jess182 on 5/23/2025 in #help
Incorrect documentation example (partial mocking)
Sorry for the confusion. The above example looks wrong to me. If you need to replace the implementation of method, you need to use stub function from @std/testing/mock:
import { assertEquals } from "jsr:@std/assert";
import { assertSpyCall, assertSpyCalls, stub } from "jsr:@std/testing/mock";

class UserService {
async getUser(id: string) {
// Complex database query
return { id, name: "Database User" };
}

async formatUser(user: { id: string; name: string }) {
return {
...user,
displayName: user.name.toUpperCase(),
};
}

async getUserFormatted(id: string) {
const user = await this.getUser(id);
return this.formatUser(user);
}
}

Deno.test("partial mocking with spies", async () => {
const service = new UserService();

// Only mock the getUser method
const getUserSpy = stub(
service,
"getUser",
() => Promise.resolve({ id: "test-id", name: "Mocked User" }),
);

try {
// The formatUser method will still use the real implementation
const result = await service.getUserFormatted("test-id");

assertEquals(result, {
id: "test-id",
name: "Mocked User",
displayName: "MOCKED USER",
});

// Verify getUser was called with the right arguments
assertSpyCalls(getUserSpy, 1);
assertSpyCall(getUserSpy, 0, {
args: ["test-id"],
});
} finally {
getUserSpy.restore();
}
});
import { assertEquals } from "jsr:@std/assert";
import { assertSpyCall, assertSpyCalls, stub } from "jsr:@std/testing/mock";

class UserService {
async getUser(id: string) {
// Complex database query
return { id, name: "Database User" };
}

async formatUser(user: { id: string; name: string }) {
return {
...user,
displayName: user.name.toUpperCase(),
};
}

async getUserFormatted(id: string) {
const user = await this.getUser(id);
return this.formatUser(user);
}
}

Deno.test("partial mocking with spies", async () => {
const service = new UserService();

// Only mock the getUser method
const getUserSpy = stub(
service,
"getUser",
() => Promise.resolve({ id: "test-id", name: "Mocked User" }),
);

try {
// The formatUser method will still use the real implementation
const result = await service.getUserFormatted("test-id");

assertEquals(result, {
id: "test-id",
name: "Mocked User",
displayName: "MOCKED USER",
});

// Verify getUser was called with the right arguments
assertSpyCalls(getUserSpy, 1);
assertSpyCall(getUserSpy, 0, {
args: ["test-id"],
});
} finally {
getUserSpy.restore();
}
});
9 replies
DDeno
Created by KyleJune on 5/4/2025 in #help
Coverage for child processes
That feature is not implemented yet. It's tracked in this issue https://github.com/denoland/deno/issues/16440
10 replies
DDeno
Created by ioB on 2/16/2025 in #help
Help compiling preact
No description
14 replies
DDeno
Created by ioB on 2/16/2025 in #help
Help compiling preact
I think you need to load your script with type="module" instead of type="text/javascript" because the output format is in ESM. I was able to run the example above with:
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<script src="./out.js" type="module"></script>
</head>
<body>
<div id="app"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<script src="./out.js" type="module"></script>
</head>
<body>
<div id="app"></div>
</body>
</html>
14 replies
DDeno
Created by Pengling on 2/17/2025 in #help
Cannot copy files from `AppData/Local/` despite --allow-all flag
Note: If the operation is denied by Deno's permission system, then NotCapable error is thrown
6 replies
DDeno
Created by Pengling on 2/17/2025 in #help
Cannot copy files from `AppData/Local/` despite --allow-all flag
PermissionDenied is thrown when the operation is denied by OS, not Deno. Does your user account have appropriate access to both source and target?
6 replies
DDeno
Created by Mqx on 3/11/2024 in #help
Import SCSS in TS files
Do you suppose the use of declare module syntax will resolve the above error? A feature request with a supposed example would be helpful
51 replies
DDeno
Created by Mqx on 3/11/2024 in #help
Import SCSS in TS files
I don't think it's immediately a bug, but support of such situation can be added/suggested in Deno.
51 replies
DDeno
Created by Mqx on 3/11/2024 in #help
Import SCSS in TS files
I don't think we have other solution than @ts-ignore. Looks like something need to be fixed (supported) in deno lsp and deno check
51 replies
DDeno
Created by ChilliSniff on 9/24/2022 in #help
Request.body.getReader() into Uint8Array typed array
(The answer to the original question) @( ¬‿¬) I think you can use new Uint8Array(await o_request.arrayBuffer())
11 replies
DDeno
Created by ChilliSniff on 9/24/2022 in #help
Request.body.getReader() into Uint8Array typed array
Ok. Fair Enough. Let's add readable stream support to readAll.
11 replies
DDeno
Created by ChilliSniff on 9/24/2022 in #help
Request.body.getReader() into Uint8Array typed array
though I'm not sure if we should overload it to readAll
11 replies
DDeno
Created by ChilliSniff on 9/24/2022 in #help
Request.body.getReader() into Uint8Array typed array
I agree with having utility for that (read all contents from ReadableStream)
11 replies