Skip to content

Instantly share code, notes, and snippets.

@christopherkade
Created April 2, 2019 07:40
Show Gist options
  • Save christopherkade/6df711074210b7104c06f2533403e19a to your computer and use it in GitHub Desktop.
Save christopherkade/6df711074210b7104c06f2533403e19a to your computer and use it in GitHub Desktop.
Unit testing example 03
function add(x, y) {
// Check if the parameters are numbers
// If not, throw an error
if (isNaN(x) || isNaN(y)) {
throw new Error("Parameter is not a number !")
}
return x + y
}
describe("add method", () => {
it("should throw an error if NaN is given as parameter", () => {
expect(add).toThrow()
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment