diff --git a/MOCHA/operations.js b/MOCHA/operations.js new file mode 100644 index 0000000..b34f814 --- /dev/null +++ b/MOCHA/operations.js @@ -0,0 +1,12 @@ +module.exports.multiply = function (x, y) { + return x * y; +}; +module.exports.add = function (x, y) { + return x + y; +}; + +module.exports.multiplyAsync = function (a, b, callback) { + setTimeout(function () { + callback(a * b); + }, 1000); +}; \ No newline at end of file diff --git a/MOCHA/operations.test.js b/MOCHA/operations.test.js new file mode 100644 index 0000000..c85f620 --- /dev/null +++ b/MOCHA/operations.test.js @@ -0,0 +1,32 @@ +var operations = require('./operations'); + +it('should multiply two numbers', function () { + var expectedResult = 15; + var result = operations.multiply(3, 5); + if (result !== expectedResult) { + throw new Error( + `Expected ${expectedResult}, but got ${result}` + ); + } +}); +it('should add two numbers', function () { + var expectedResult = 16; + var result = operations.add(9, 7); + if (result !== expectedResult) { + throw new Error( + `Expected ${expectedResult}, but got ${result}` + ); + } +}); + +it('shoud async multiply two numbers', function (done) { + var expectedResult = 12; + operations.multiplyAsync(4, 3, function (result) { + if (result !== expectedResult) { + throw new Error( + `Expected ${expectedResult}, but got ${result}` + ); + } + done(); + }); +}); diff --git a/MOCHA/package.json b/MOCHA/package.json new file mode 100644 index 0000000..dd71ea5 --- /dev/null +++ b/MOCHA/package.json @@ -0,0 +1,10 @@ +{ + "name": "testapp", + "version": "1.0.0", + "scripts": { + "test": "mocha *.test.js" + }, + "devDependencies": { + "mocha": "^3.2.0" + } +} \ No newline at end of file