Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const expect = require('chai').expect;
- const calc = require('../../app/calc');
- describe('Calc method', () => {
- const testData = {
- negative: [
- { a: true },
- { a: 'foo', b: 2 },
- { a: 1, b: { name: 'John' } },
- { a: null, b: 'bar' }
- ],
- sumPositive: [
- { a: -1, b: 1, sum: 0 },
- { a: 10, b: 101, sum: 111 },
- { a: 11, b: -3, sum: 8 },
- { a: -42, b: 12, sum: -30 },
- ],
- multiplicationPositive: [
- { a: -1, b: 1, multiplication: -1 },
- { a: 10, b: 101, multiplication: 1010 },
- { a: 11, b: -3, multiplication: -33 },
- { a: -42, b: 12, multiplication: -504 },
- ],
- };
- testData.negative.forEach(({ a, b }) => {
- it(`should throw an error if not a number parameters a = ${a} and b = ${b} passed`, () => {
- const addWithError = () => calc.add(a, b);
- expect(addWithError).to.throw(TypeError);
- });
- });
- testData.sumPositive.forEach(({ a, b, sum }) => {
- it(`should return valid value ${sum} for sum of numbers ${a} and ${b}`, () => {
- expect(calc.add(a, b)).to.equal(sum);
- });
- });
- testData.negative.forEach(({ a, b }) => {
- it(`should throw an error if not a number parameters a = ${a} and b = ${b} passed`, () => {
- const multiplyWithError = () => calc.multiply(a, b);
- expect(multiplyWithError).to.throw(TypeError);
- });
- });
- testData.multiplicationPositive.forEach(({ a, b, multiplication }) => {
- it(`should return valid value ${multiplication} for multiplication of numbers ${a} and ${b}`, () => {
- expect(calc.multiply(a, b)).to.equal(multiplication);
- });
- });
- });
Add Comment
Please, Sign In to add comment