Implement your own Testing Library | Frontend Problem Solving | JavaScript Interview Question
@Yomesh Gupta

JavaScriptBeginner
1082
Do you see value in our efforts?

Devtools Tech is a free platform for Frontend Engineers. It takes a lot of time, effort, and finanical resources to keep the platform running. If you see any value in our work and would like to support us then you can do using the following options.

InternationalDomestic

In this question, you need to replicate the popular testing library jest functionality. You must implement the utility expect provided by the jest library.

// Syntax
customExpect(actual).toBe(expected);
customExpect(actual).not.toBe(expected);


customExpect(3).toBe(3); // no error | Do not return anything
customExpect(2).toBe(3); // should throw an error

customExpect(2).not.toBe(3); // no error | Do not return anything
customExpect(2).not.toBe(2); // should throw an error

Your customExpect function should support the functionality of toBe and not.toBe.

P.S. We have provided a stopwatch timer at the top. Start the timer when you are about to try this question and try to finish within 15-20 mins.

Bonus


Once you are successfully done with this then try to implement more methods from jest. Find full list here: https://jestjs.io/docs/expect

Loading IDE...