2017-11-04 5 views
0

私は単体テストに「モカ」と「チャイ」を使用しようとしていますが、テスト結果に問題があります。 ご覧ください。mocha + chaiによるユニットテストは常に成功

UnitTest.spec.ts

import PostgresService from "../src/Services/PostgresService" 
import {expect} from "chai" 
import 'mocha' 

describe('Postgres Override Test function',() => { 
    it('should return any number but not zero', async() => { 
     let client = new PostgresService(); 
     let result = await client.getLatestCMD("Servo"); 
     try{ 
      console.log("Type : " + typeof(result)); 
      console.log("Value : " + result.rows[0].id); 
      expect(result.rows[0].id).to.equal(0)   
     }catch(error){ 

     } 
    }) 
}) 

enter image description here

+1

try catchブロックを削除してください – Liroy

+0

@ LiroyLeshed.comそれは仕事です!しかし、なぜ? – kosterz

+0

多くのユニットテストフレームワークは、例外をスローすることによってエラーを示します。あなたが静かに例外をキャッチすると、シグナルメカニズムを効果的に無効にします。 –

答えて

1

実際にあなたのexpect機能を実行しようとするcatchブロックを削除します。

tryブロックでエラーが返された場合、JavaScriptインタプリタはcatchブロックに移動し、前者は実行されません。

関連する問題