Created
April 2, 2019 07:40
-
-
Save christopherkade/6df711074210b7104c06f2533403e19a to your computer and use it in GitHub Desktop.
Unit testing example 03
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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