dimanche 22 avril 2018

Error: Cannot find module mocha

Hi I am currently trying to write some unit tests using Mocha, however when I try to import one of my local modules it cannot seem to find it and spits out the following error:

Error: Cannot find module '../../communication/Model/RequestData'

This seems to happen with any of my local modules.

My Current directory goes as follows:

Lib
    src
        __tests__
            communication
                DataChannel.test.ts
        communication
            models
                RequestData.ts
            DataChannel.ts

My current tests import the following

import { assert, should } from 'chai'
import { describe } from 'mocha';
import { spy } from 'sinon';
import { IRequestData, RequestData } from '../../communication/models/RequestData';
import DataChannel from '../../communication/DataChannel';

Here is how I export my files:

RequestData.ts:

/**
 * @description Interface for request data
 */
export interface IRequestData {
    resource: string,
    data: any
}

/**
 * @class Model for request data
 */
export class RequestData implements IRequestData {
    public resource: string = '';
    public  data: any = null;
}

and here is my DataChannel.ts:

import { IRequestData } from "./models/RequestData";

/**
 * @class This class handles all data communication
 */
export default class DataChannel {
    /**
     * @constructor Constructor for the class
     */
    constructor() {

    }

    /**
     * @method Request Makes a request to the endpoint specified 
     * @public
     * @param data The data we are passing over to the endpoint
     */
    static Request(data: IRequestData): void {
        throw new Error("Method not implemented.");
    }
}

Aucun commentaire:

Enregistrer un commentaire