2017-12-08 6 views
1

問題は、mocha-typescriptがdescribeが定義されていないというエラーをスローし続けていることです。typescript mocha describeは関数ではありません

TypeError: mocha_typescript_1.describe is not a function 
    at DatabaseTest.WrongPath (test/database_test.ts:21:9) 
    at Context.<anonymous> (node_modules/mocha-typescript/index.ts:218:22) 

マイtsconfig.json

{ 
     "compilerOptions": { 
     "target": "es6", 
     "module": "commonjs", 
     "outDir": "dist", 
     "sourceMap": true, 
     "lib": ["es6"], 
     "experimentalDecorators": true, 
     "emitDecoratorMetadata": true, 
     "noUnusedLocals": true, 
     "noUnusedParameters": true, 
     "typeRoots": [ 
      "./node_modules/@types" 
     ], 
     "types": [ 
      "node", "mocha", "chai" 
     ] 
     }, 
     "include": [ 
     "src/**/*.ts", 
     "test/**/*.ts" 
     ], 
     "exclude": [ 
     "node_modules" 
     ] 
    } 

{ 
     //omitted 
     "main": "App.js", 
     "scripts": { 
     "pretest": "tsc", 
     "test": "nyc mocha --require ts-node/register test/**/*_test.ts ", 
     "watch": "mocha-typescript-watch", 
     "prepare": "tsc" 
     }, 

     // ommitted 

     "dependencies": { 
     "@types/chai": "^4.0.6", 
     "@types/jsesc": "^0.4.29", 
     "@types/mocha": "^2.2.44", 
     "@types/node": "^8.0.53", 
     "@types/sqlite3": "^3.1.1", 
     "chai": "^4.1.2", 
     "express": "^4.16.2", 
     "express-longpoll": "0.0.4", 
     "jsesc": "^2.5.1", 
     "mocha": "^4.0.1", 
     "mocha-typescript": "^1.1.12", 
     "nyc": "^11.3.0", 
     "reflect-metadata": "^0.1.10", 
     "sequelize": "^4.26.0", 
     "sequelize-typescript": "^0.6.1", 
     "source-map-support": "^0.5.0", 
     "sqlite3": "^3.1.13", 
     "ts-events": "^3.2.0", 
     "ts-node": "^3.3.0", 
     "typescript": "^2.6.2", 
     "typings": "^2.1.1" 
     } 
    } 

database_test.tsマイpackage.json:

//Unit testing script for Database.ts 
    /// <reference path="../node_modules/mocha-typescript/globals.d.ts" /> 
    //// <reference path="../node_modules/@types/mocha/index.d.ts" /> 

    import { suite, test, describe, slow, timeout } from "mocha-typescript" 
    import { assert } from "chai"; 
    import 'mocha' 

    @suite(slow(1000), timeout(3000)) 
    export class SampleTest { 

     @test testFunc(){ 
      describe("Sample function",()=>{ 
       it("Should succeed without any problems", (done) => { 
        assert.isTrue(true); 
        done(); 
       }) 
      }); 
     } 
    } 

全ログ:

> [email protected] pretest /home/user/folder/project 
    > tsc 


    > [email protected] test /home/user/folder/project 
    > nyc mocha --require ts-node/register test/**/*.ts 



     SampleTest 
     1) testFunc    

     0 passing (13ms) 
     1 failing 

     1) SampleTest 
      testFunc: 
     TypeError: mocha_typescript_1.describe is not a function 
      at DatabaseTest.WrongPath (test/database_test.ts:21:9) 
      at Context.<anonymous> (node_modules/mocha-typescript/index.ts:218:22) 


    ----------|----------|----------|----------|----------|----------------| 
    File  | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines | 
    ----------|----------|----------|----------|----------|----------------| 
    All files | Unknown | Unknown | Unknown | Unknown |    | 
    ----------|----------|----------|----------|----------|----------------| 
    npm ERR! Test failed. See above for more details. 

あなたは、私がこのような設定typeRootstypestsconfig.jsonで、import mocha 2つの異なるタイプのdefinitonファイルとして複数のものを試してみた見ることができるように。それらのどれも働かなかったし、すべての可能な組み合わせで絡まっている。

私は今、しばらくの間、typescript-mochaを稼働させようとしてきましたが、時々動作します。私は持っていない明確な説明が、私は確かに1つが好きです。

答えて

0

ダブルキーワード宣言のためにエラーが出ています。 明らかにimport 'mocha'は、describeというキーワードを宣言するのに十分です。

私は単に

import { suite, test, slow, timeout } from "mocha-typescript" 

import { suite, test, describe, slow, timeout } from "mocha-typescript" 

からインポート行を調整しなければなりませんでした

関連する問題