Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
  • Loading branch information
imteekay committed Jan 21, 2024
1 parent 2e553a2 commit 951dd58
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
function describe(testSuiteName, func) {
console.log(`beginning test suite ${testSuiteName}`);
try {
func();
console.log(`successfully completed test suite ${testSuiteName}`);
} catch ({ testCaseName, errorMessage }) {
console.error(
`failed running test suite ${testSuiteName} on test case ${testCaseName} with error message ${errorMessage}`
);
}
}

function it(testCaseName, func) {
console.log(`beginning test case ${testCaseName}`);
try {
func();
console.log(`successfully completed test case ${testCaseName}`);
} catch (errorMessage) {
throw { testCaseName, errorMessage };
}
}

function expect(actual) {
return {
toExist: () => {
if (actual === null || actual === undefined) {
throw `expected value to exist but got ${actual}`;
}
},
toBe: (expected) => {
if (actual !== expected) {
throw `expected ${JSON.stringify(actual)} to be ${JSON.stringify(
expected
)}`;
}
},
toBeType: (type) => {
if (typeof actual !== type) {
throw `expected ${JSON.stringify(
actual
)} to be of type ${type} but got ${typeof actual}`;
}
},
};
}

0 comments on commit 951dd58

Please sign in to comment.