What/Why Unittest | Unittest with Angular 2+

  • What is a unit test?
  • Why write unit tests?
  • How to setup an Angular test?
  • Ok, now how do we write unit tests?

What is a unit test?

function sum(...args) {
return args.reduce((total, value) => total + value, 0);
it('should sum a range of numbers correctly', () => {
// Arrange
const expectedValue = 55;
const numsToTest = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

// Act
const total = sum(...numsToTest);

// Assert

But Why Unittest?

How do you set up an Angular test?

ng test

How to write and how does the test run?

How to test a service(QuoteService)?

How to test a component (QuotesComponent)



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store