DEV Community

Discussion on: An Introduction to testing in Javascript

Collapse
 
michaelcurrin profile image
Michael Currin

Indeed.

Also mocked tests won't depend on the 3rd party service from being up as your tests might fail when it is down or just when your network is slow.

Mocking also is sandboxed. If you frontend app needs to post to Twitter and you have 100 cases to test against the API using good and bad data and various made up user profiles, then a mock will mean you don't risk actually creating a tweet (or buying a product or whatever your app does). And will work without an API key.
It just means you have to keep your mock close to the real interface.

I have read a TDD book and it has a nice section on when to mock and when not too, so it depends on what you want to achieve