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

Back to basics

The companion source code includes a class named MathDemo. This class allows us to perform the pow calculation in a few different ways. One of them is the synchronous pow function:

public pow(base: number, exponent: number) {   let result = base; 
  for (let i = 1; i < exponent; i++) { 
    result = result * base; 
  } 
  return result; 
} 

As we learned in Chapter 9, Automating Your Development Workflow, we can test the method declared in the preceding function using the following test case:

it("Should return the correct numeric value for pow", () => { 
  const math = new MathDemo(); 
  const result = math.pow(2, 3); 
  const expected = 8; 
  expect(result).to.be.a("number"); 
  expect(result).to.equal(expected); 
}); 

We can then use the nyc command with ...

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