A lovely javascript testing framework -- want to contribute? join us in https://gitter.im/mochajs/contributors
juergba on karma
type check before calling retri… (compare)
Hey guys!
In Chrome 76 they disabled 'disable-infobars' flag.
I found and replacement for this,
...but can't get how can I pass this in chrome args. Can anybody advise?
npm i mochawesome
mocha --reporter mochawesome
//why my 2nd test fails? any suggestions?
/*************calculate.js************/
function calculateSquare(number, callback) {
setTimeout(() => {
if (typeof number !== 'number') {
callback('Argument of type number is expected');
return;
}
const result = number * number;
callback(null, result);
}, 1000);
}
module.exports = calculateSquare;
/*************calculate.test.js************/
const calculateSquare = require('../calculate.js');
const expect = require('chai').expect;
describe('calculateSquare', function () {
it('should return 4 if passed 2', function (done) {
calculateSquare(2, function (error, result) {
console.log('callback got called');
expect(result).to.equal(4);
done(); // call this when Async!
})
});
it('it should return an error if passed a string', function (done) {
calculateSquare('string', function (error, result) {
expect(error).to.not.equal(null);
expect(error.message).to.equal('Argument of type number is expected');
done();
})
})
});
calculateSquare
callback got called
✓ should return 4 if passed 2 (1008ms)
1) it should return an error if passed a string
1 passing (2s)
1 failing
1) calculateSquare
it should return an error if passed a string:
Uncaught AssertionError: expected null to not equal null
+ expected - actual
at /Users/nadia/test/calculate.test.js:15:28
at Timeout.setTimeout [as _onTimeout] (calculate.js:8:5)
npm ERR! Test failed. See above for more details.
"test": "mocha --require babel-core/register"
{
"presets": [
[
"env",{"targets": {"node": "current"}}
]
]
}
const assert = require("chai").assert;
const sayHello = require("../app").sayHello;
const addNum = require("../app").addNum;
//const app = require("../app");
describe("App", function() {
it("app should return hello", function() {
assert.equal(sayHello(), "hello");
});
it("app it should be a string", function() {
assert.typeOf(sayHello(), "string");
});
it("should return 15", function() {
assert.equal(addNum(8), "15");
});
it("should be a number", function() {
assert.typeOf(addNum(5), "number");
});
});
const mocha = new Mocha({
reporter: "json"
});
const pathFile = `./test/${title}`;
mocha.addFile(pathFile);
const runner = mocha.run(failures => {
console.log(failures);
if (failures) console.log(true);
});
console.log(runner);