错误:无法找到模块mocha

时间:2018-04-22 15:32:48

标签: javascript typescript testing ecmascript-6 mocha

您好我正在尝试使用Mocha编写一些单元测试,但是当我尝试导入我的一个本地模块时,似乎无法找到它并吐出以下错误:

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

这似乎与我的任何本地模块一起发生。

我的当前目录如下:

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

我当前的测试会导入以下内容

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';

以下是我导出文件的方式:

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;
}

这是我的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.");
    }
}

1 个答案:

答案 0 :(得分:1)

也许尝试在全球范围内安装摩卡。

npm install --global mocha