Most JavaScript projects use testing frameworks like Jest or Mocha that provide functions such as test
and expect
.
Your task is to implement a very minimal testing utility that mimics this behavior:
Implement a global test(name, fn)
function that:
fn
.Implement a global expect(received)
function that returns an object with:
toBe(expected)
→ asserts strict equality.toEqual(expected)
→ asserts deep equality (recursive object/array check).test('addition works', () => {
expect(1 + 2).toBe(3);
});
test('array equality', () => {
expect([1, 2, 3]).toEqual([1, 2, 3]);
});
Output:
✅ addition works
✅ array equality
If a test fails, it should show ❌ with the test name.
toBe
and toEqual
.