Getting started
Let's discover Miette in less than 5 minutes.
Getting Started
Get started by installing Miette.
npm install miette --save
Instrument your functions
Using miette you can make custom error objects that allow you to
@miette("foo::bar::baz", FooBarBaz.toString())
class ShouldBeFalseError extends Error {
diagnostic = {
help: "Please consult the guides at http://github.com/foo/bar#guides",
};
snippets = [
{
context: "if (true)",
highlight: "This will always be called",
},
];
}
function FooBarBaz() {
// eslint-disable-next-line no-constant-condition
if (true) {
try {
throw new ShouldBeFalseError("Should make things dynamic");
} catch (error) {
if (error instanceof Error) {
console.log(error.stack);
expect(error.stack).toMatchSnapshot();
}
}
}
}
FooBarBaz();
The final output will look like the following!
Error: foo::bar::baz
ร Should make things dynamic
โญโโโ[miette.test.ts:25:15]
0 โ function FooBarBaz() {
1 โ // eslint-disable-next-line no-constant-condition
2 โ if (true) {
ยท โโโโโฌโโโโ
ยท โฐโโ This will always be called
3 โ try {
4 โ throw new ShouldBeFalseError(\"Should make things dynamic\");
5 โ } catch (error) {
6 โ if (error instanceof Error) {
7 โ console.log(error.stack);
8 โ expect(error.stack).toMatchSnapshot();
9 โ }
10 โ }
11 โ }
12 โ }
13 โ
โฐโโโ
โฝ Please consult the guides at http://github.com/foo/bar#guides
Contribute back!
Help improve Miette by opening up issues with your use cases of Miette and reproductions of errors that don't look as expected!