Intentions
Loading "Write an Intentional Test"
Run locally for transcripts
You have a
greet
function that should greet the user by their name. That's the intention behind it. And here's its implementation:function greet(name: string) {
return `Hello, ${name}!`
}
๐จโ๐ผ Now your job is to add an automated test for the
greet
function
(you can put it in the same greet.ts
file) so you can run npx tsx
greet.ts
any time you want to check whether that functions works as
intended.As a reminder, this is what any automated test comes down to:
// Run the code and get the *actual* result.
let result = code(...args)
// Compare the actual with the expected results.
if (result !== expected) {
// Alert us if the two results don't match
// as that likely means a bug in the code.
throw new Error(`Expected "${expected}" but got ${result}`)
}