-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
SvelteExercise involves the SvelteKit frameworkExercise involves the SvelteKit frameworkTypeScriptExercise includes TypeScript codeExercise includes TypeScript code
Description
When creating unit tests, it's important to ensure they're isolated and not depending on external services. One way to achieve this is to create mock objects that abstract layers of your application. Copilot Chat can help you generate the code you need to create these mock objects.
Example scenario
Imagine a website built with TypeScript which displays a list of runners. You have a service which fetches the runners from a database, and the server-side code which uses this service. You want to test the server-side code, but you don't want to make a call to the database. You can ask Copilot Chat to generate a mock object for the service.
// SvelteKit example at +page.server.ts
import service from './service';
export async function load({ params }) {
const runner = await service.getRunner(params.id);
return {
runner
};
}Example prompt
Create a unit test to ensure the service is called correctly. Mock the service object.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
SvelteExercise involves the SvelteKit frameworkExercise involves the SvelteKit frameworkTypeScriptExercise includes TypeScript codeExercise includes TypeScript code