I moved away from DEV for blogging, so now I'm barely active here. If you're still interested in my articles, you can check them on my site: https://luke.sh/articles
Nice example! I seen some similar posts in which they tested the values of the actual properties instead of the output of methods, which is a very bad practice, because the internal state isn't relevant to unit testing, just the surface of contact with the external world. So:
// Doing it like in your example, which is ideal:constinstance=newClass("value");constoutput=instance.method();expect(output).toBe("expected-value");// Bad practice I seen:constinstance=newClass("value");expect(instance.value).toBe("value");
Nice example! I seen some similar posts in which they tested the values of the actual properties instead of the output of methods, which is a very bad practice, because the internal state isn't relevant to unit testing, just the surface of contact with the external world. So:
Thanks for sharing! Cheers!
Thanks for sharing this Luke! Definitely good to know, I'm pretty new to writing my own tests so trying to learn about best practices