2017-12-08 10 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 및 두 개의 서로 다른 종류의 definiton 파일로 여러 가지를 시도했습니다 볼 수 있듯이. 그들 중 누구도 일하지 않았고 나는 모든 가능한 조합에 얽혀 있습니다.

나는 지금 잠시 동안 typescript-mocha를 실행하려고 노력 해왔다. 때로는 작동하지만 가끔은 작동하지 않는다. 내가 갖고 있지 않은 분명한 설명이지만, 나는 분명히 그것을 좋아할 것입니다.

답변

0

이중 키워드 선언으로 인해 오류가 발생했습니다. 분명히 import 'mocha'describe 키워드를 선언하기에 충분합니다.

단순히

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

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

에서 가져 오기 라인을 조정했다