Created
October 2, 2019 18:18
-
-
Save jennjwill/e3760a4b23ec6506ea6ae462befbd86e to your computer and use it in GitHub Desktop.
spec test example
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
//import {math} from './math.js'; | |
// 6 Assume that there is a `math.js` file that performs various mathematical operations on pairs of integers. Design a Jasmine suite with the following unit tests. | |
// - A spec for the addition(+) operation. (test.add(num1, num2)) | |
// - A spec for the subtraction(-) operation. (test.subtract(num1, num2)) | |
// - A spec for the multiplication(*) operation. (test.multiply(num1,num2)) | |
// - A spec for the division(/) operation. (test.divide(num1, num2)) | |
// - A spec to throw an error if an operation tries to divide by zero. | |
//add the associated specs under each comment | |
//the functions are implemented by calling the object test and then the method (test.add(num1,num2)) | |
//Spec for addition operation | |
//Spec for subtraction operation | |
//Spec for multiplication operation | |
//Spec for division operation | |
//Spec for throwing an error if there is a divide by zero | |
describe("math", () => { | |
let test; | |
beforeEach( () => { | |
test = new math(); | |
}); | |
describe('testing basic math operations', () => { | |
it("should sum two numbers", () => { | |
expect(test.add(2, 2)).toEqual(4); | |
}); | |
it("should give result of subracting one number from another", () => { | |
expect(test.subtract(10, 5)).toEqual(5); | |
}); | |
it("should give result of multiplying two numbers", () => { | |
expect(test.multiply(5, 5)).toEqual(25); | |
}); | |
it("should give result of division", () => { | |
expect(test.divide(10, 5)).toEqual(2); | |
expect(test.divide(5, 0)).toThrowError(); | |
}) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment