DEV Community

Discussion on: The three A’s of Unit Testing

Collapse
 
lukeshiru profile image
Luke Shiru

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:

const instance = new Class("value");
const output = instance.method();
expect(output).toBe("expected-value");

// Bad practice I seen:

const instance = new Class("value");
expect(instance.value).toBe("value");
Enter fullscreen mode Exit fullscreen mode

Thanks for sharing! Cheers!

Collapse
 
coderjay06 profile image
Jay Cruz

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