'Optimizing Mocha Chai testing of a simple JavaScript application

I am tasked with testing this index.js file using Mocha Chai Testing:

module.exports = {
  
  addDetails: function() {
    let data =[]
    data.push("one");
    return data
  },

  deleteDetails: function() {
    let data =["one" , "two"]
    data.splice(0 , 1)
    return data
  },

  editDetails: function() {
    let data =["one"]
    data.splice(0 , 1 , "three")
    return data
  },

  updateDetails: function() {
    let data = ["one" , "three"]
    data.splice(1 , 0 , "two")
    return data
  },

  detailsPop: function() {
    let numb = ["one" , "two"]
    numb.pop()
    return numb
  },

  concatData: function() {
    let data1 = ["one"]
    let data2 = ["two"]
    let result = data1.concat(data2)
    return result
  }
 }

I am using this virtual environment as my work environment (HackerRank):

Environment

Here is the indextest.js file I wrote testing each of the functions in index.js:

var assert = require("assert");
var crud = require('../src/index');

describe('Crud application', function(){
    //write your code here

    it("testing addDetails", function() {
      assert.equal(crud.addDetails(), [ 'one' ], 'addDetails works!');
    });

    it("testing deleteDetails", function() {
      assert.equal(crud.deleteDetails(), [ 'two' ], 'deleteDetails works!');
    });

    it("testing editDetails", function() {
      assert.equal(crud.editDetails(), [ 'three' ], 'editDetails works!');
    });

    it("testing updateDetails", function() {
      assert.equal(crud.updateDetails(), [ 'one', 'two', 'three' ], 'updateDetails works!');
    });

    it("testing detailsPop", function() {
      assert.equal(crud.detailsPop(), [ 'one' ], 'detailsPop works!');
    });

    it("testing concatData", function() {
      assert.equal(crud.concatData(), [ 'one', 'two' ], 'concatData works!');
    });
});

My test performance is being scored using score.sh

npm install
npx nyc mocha --timeout 10000 --reporter mocha-junit-reporter --exit
npx nyc --reporter=clover mocha --timeout 10000 --reporter mocha-junit-reporter --exit
node xml-merge.js

My indextest.js is not accepted by score.sh. Here is my console:

user@workspaceew8g7c7x4yebmr8m:/projects/challenge$ npm test

[email protected] test /projects/challenge mocha --timeout 10000 --reporter mocha-junit-reporter --collectCoverageFrom=src/index.js --exit

npm ERR! Test failed. See above for more details. user@workspaceew8g7c7x4yebmr8m:/projects/challenge$

What is a better way to test using Mocha Chai? How could I change my indextest.js file to provide better testing for my index.js?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source