title: Testing class function in JavaScript, Mocha and Chai
body: <p>I have created a simple bot and want to test a basic class function called <code>getComputerChoice</code>. I am using mocha and chai to test this function but when I run it, it says <code>TypeError: getComputerChoice is not a function</code>. I have tried finding a solution but haven't had any luck. </p>
  
  <p>Here is the code below:</p>
  
  <p>game.js</p>
  
  <pre><code>class PaperScissorsRockCommand {
      constructor() {}
  
      getComputerChoice() {
          const choices = ['paper', 'scissors', 'rock'];
          const chance = Math.floor(Math.random() * 3);
          return choices[chance];
      }
  }
  
  module.exports = PaperScissorsRockCommand;
  </code></pre>
  
  <p>game.spec.js</p>
  
  <pre><code>const assert = require('chai').assert;
  const getComputerChoice = require('../commands/games/paperscissorsrock').getComputerChoice;
  
  describe('Paper, Scissors, Rock', function () {
      it('Return paper', function () {
          let result = getComputerChoice();
          assert.equal(result, 'paper');
      });
  });
  </code></pre>