Unit tests are there to drive us through development of the higher level API. They are going to help us develop and test the logic we build on top of the native transport, not the logic a given browser vendor built into their XMLHttpRequest implementation.
Stubbing and mocking are two ways to create objects that mimic real objects in tests. Along with
fakes
anddummies
, they are often collectively referred to astest doubles
.
They usually implemented on tests when original implementations is awkward or when we need to isolate an interface from its dependencies.
...tests document your API.
... is perhaps the most valuable tool when it comes to producing clean code and removing duplication.