Files
PicAnalysis/backend/tests/setup.ts

32 lines
597 B
TypeScript
Raw Normal View History

/**
* Jest Test Setup
*/
// Make this a module
export {};
// Extend Jest matchers
declare global {
namespace jest {
interface Matchers<R> {
toBeValidUUID(): R;
}
}
}
// Custom matchers
expect.extend({
toBeValidUUID(received: string) {
const uuidRegex =
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
const pass = uuidRegex.test(received);
return {
pass,
message: () =>
pass
? `Expected ${received} not to be a valid UUID`
: `Expected ${received} to be a valid UUID`,
};
},
});