Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

checkForShip is not a function

I am attempting to follow the mocha chai test tutorial line by line. I got past the first test and it worked fine, but when I get to the 2nd test attempting to test it for an imagined spot on the battleship board, i am getting, "CheckForShip is not a function" but the 1st test, where it calls the function, works fine. According to the tutorial, i should be getting an assertion error, but I am getting the error I mentioned.

Here is my code:

var expect = require('chai').expect;

describe('checkForShip', function(){
    var checkForShip = require('../game_logic/ship_methods').checkForShip;

    it('should correctly report no ship at a given players coordinate', function(){

        player = {
            ships: [
                {
                    locations: [[0, 0]]
                }
            ]
        };

        expect(checkForShip(player, [9, 9])).to.be.false;

    });
});

and the function it calls:

function checkForShip(){

}

module.exports.CheckForShip = checkForShip;

1 Answer

I have not completed the mocha course myself so I don't know much about the project you are doing, but one discrepancy I notice is that you export the function as CheckForShip but import checkForShip (notice the capitalization difference). If you change your import statement to:

var checkForShip = require('../game_logic/ship_methods').CheckForShip;

Then that will likely fix your issue. Though ideally you shouldn't be mixing the case between the import/export name and the actual function name to begin with. So renaming all references to checkForShip to ensure they all use the same case would be ideal.

d'oh! Yeah it was the capitalization. Didn't catch it. They were all supposed to be checkForShip. Thanks!