dimanche 11 mars 2018

Jest Cannot Create Objects from Imported Classes

In ChangesFactory-test.js I am importing the class I want to test like so:

import ChangesFactory from 'path/to/src/ChangesFactory'

I am trying to create an instance in a test case like this:

describe('Changes', function () {
it ('testConstructor', function() {
    // test that a username can be passed in
    let changesFactory = new ChangesFactory(USERNAME);

However, running the above code leaves the value of changesFactory undefined.

The constructor of the ChangesFactory class is written as:

export default class ChangesFactory {
constructor(value) {
    if (typeof value === 'string') {
        this.changes = new Changes(value);
    } else if (value instanceof Changes) {
        this.changes = changes;
    }
};

and I am running the command npm test ChangesFactory

I am relatively new to Jest and ES6 and am wondering if I am missing something. What could I do to test the ChangesFactory class?

Aucun commentaire:

Enregistrer un commentaire