0

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?enter image description here

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));
      }
    
    }
SiBasti
  • 45
  • 1
  • 5
  • Does this answer your question? [Which way is best for creating an object in JavaScript? Is \`var\` necessary before an object property?](https://stackoverflow.com/questions/6843951/which-way-is-best-for-creating-an-object-in-javascript-is-var-necessary-befor) – WOUNDEDStevenJones Nov 10 '21 at 21:44

1 Answers1

2

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));
    }

};
WOUNDEDStevenJones
  • 5,150
  • 6
  • 41
  • 53
  • 1
    or, you could do `module.exports = { myFunctiona(){/*code*/}, myFunctionb(){/*code*/}, myFunctionc(){/*code*/}, myFunctiond(){/*code*/} };` – 2pichar Nov 10 '21 at 22:01