JavaScript JavaScript Unit Testing Improving Our Tests Catching an Error

expect(subtraction("a","b")).to.throw('subtraction only works with numbers!') How could this not work?

expect(subtraction("a","b")).to.throw('subtraction only works with numbers!')

is my code. I have no idea what could possibly be wrong with this. But it doesn't pass.

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

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

1 Answer

Nevermind, I'm just dumb.