Update
This commit is contained in:
12
MOCHA/operations.js
Normal file
12
MOCHA/operations.js
Normal file
@@ -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);
|
||||
};
|
||||
32
MOCHA/operations.test.js
Normal file
32
MOCHA/operations.test.js
Normal file
@@ -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();
|
||||
});
|
||||
});
|
||||
10
MOCHA/package.json
Normal file
10
MOCHA/package.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "testapp",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"test": "mocha *.test.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^3.2.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user