Skip to Content
Learning TypeScript 2.x - Second Edition
book

Learning TypeScript 2.x - Second Edition

by Remo H. Jansen
April 2018
Beginner content levelBeginner
536 pages
13h 21m
English
Packt Publishing
Content preview from Learning TypeScript 2.x - Second Edition

Isolating components with Sinon.JS

We have learned that unit tests are used to test individual components, and integration tests are used to test a set of components and their interactions. When we write a unit test, and a component has a dependency on another, we will need to provide stubs, mocks, or dummies instead of real dependencies to ensure that the component is being tested in isolation. However, sometimes this can be more complicated than it sounds. Luckily, Sinon.JS can help us to ensure that our components are tested in isolation.

The following code snippet is used to test the web client of the pow web service that we described earlier in this chapter. We use Sinon.JS to define a stub for a global object named fetch. The fetch ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering TypeScript - Fourth Edition

Mastering TypeScript - Fourth Edition

Nathan Rozentals
Learning TypeScript

Learning TypeScript

Josh Goldberg
TypeScript for Beginners

TypeScript for Beginners

Bharath Thippireddy

Publisher Resources

ISBN: 9781788391474Supplemental Content