PositiveGuy
PositiveGuy

Reputation: 20182

Expected Undefined to be an object for Node Module

what the heck am I doing wrong here. Isn't a function an object in JS?

car.js

'use strict';


var Car = function(){

};

export default Car;

car-test.js

import {expect} from 'chai';
import {Car} from '../../src/car';

describe('car', () => {

    it('should have a car to work with', () => {
        expect(Car).to.be.an('object');
    });

});

UPDATE

I could even just leave the var out, not sure if that makes a difference, the var is still pointing to the same thing but I could also do this:

function Car(){

};

export default Car;

Upvotes: 2

Views: 900

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074295

a/an tests the typeof value for the item. Yes, functions are objects, but their typeof is "function".

This is just about the only place where typeof gives us more detailed information than just "object" for an object (in fact, I can't think of another one; typeof new Date is "object", typeof a regexp object is "object", etc.). typeof is fairly vague, but was specific in this one situation. :-) FWIW, I cover type checking a bit on my anemic little blog: Say what?

Upvotes: 3

Related Questions