I'm trying to get these functions defined to run some synchronous and asynchronous test cases on them with Mocha and Chai in JS, what am I doing wrong? Why is my editor marking certain lines?
module.exports = {
function myFunctiona () {
}
function myFunctionb () {
for (let i = 0; i < 10000; i++) {
new Date();
}
}
function myFunctionc(done) {
setTimeout(done, 0);
}
function myFunctiond (done) {
setTimeout(done, Math.round(Math.random() * 10));
}
}
This is a syntax error because you're defining an object with properties, but you don't have property keys. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Missing_colon_after_property_id for more information.
Typically, you'd define an object like the following (note the commas after each property too):
var object = {
property1: 'thing',
property2: function() {
return 'thing2';
}
}
so to change your functions to properties, set the property key as the function name, and then assign a function to it like:
module.exports = {
myFunctiona: function () {
//nothing
},
myFunctionb: function () {
for (let i = 0; i < 10000; i++) {
new Date();
}
},
myFunctionc: function (done) {
setTimeout(done, 0);
},
myFunctiond: function (done) {
setTimeout(done, Math.round(Math.random() * 10));
}
};