JavaScript JavaScript Unit Testing Improving Our Tests Catching an Error

Eden Gomez
Eden Gomez
22,289 Points

Can somebody please give me a hint with what method should I use for this challenge?

var expect = require('chai').expect

describe('subtraction', function () { var subtraction = require('../WHEREVER') it('only works with numbers', function () { // YOUR CODE HERE expect(substraction(number1, number2).to.be.NaN); }) })

subtraction_spec.js
var expect = require('chai').expect

describe('subtraction', function () {
  var subtraction = require('../WHEREVER')  
  it('only works with numbers', function () {
    // YOUR CODE HERE
  })
})
subtraction.js
function subtraction (number1, number2) {
  if (typeof number1 !== 'number' || typeof number2 !== 'number') {
    throw Error('subtraction only works with numbers!')
  }
  return number1 - number2
}