January 2018
Beginner
658 pages
13h 10m
English
Now, we'll create an if statement for the test. If the response value is not equal to 44, that means we have a problem on our hands and we'll throw an error:
const utils = require('./utils');it('should add two numbers', () => { var res = utils.add(33, 11); if (res != 44){ }});
Inside the if condition, we can throw a new error and we'll use a template string as our message string because I do want to use the value that comes back in the error message. I'll say Expected 44, but got, then I'll inject the actual value, whatever happens to come back:
const utils = require('./utils');it('should add two numbers', () => { var res = utils.add(33, 11); if (res != 44){ throw new Error(`Expected 44, but got ${res}.`); ...Read now
Unlock full access