2017-02-27 27 views
1
import React from 'react'; 
import CrudApi from '../api/CrudApi'; 
import nock from 'nock'; 

describe('CrudList Component',() => { 

    it('should have users',() => { 

     afterEach(() => { 
      nock.cleanAll() 
     }) 

     CrudApi.getAll().then(
      data => {expect(data).toHaveLength(9) // this failed 
      console.log(data.length) // 10} 
     ) 
    }); 
}); 

これは私のテストケースです。getAllが10の配列を返すため、これは失敗したと考えられます。私のcmdでは、テストが合格しているのを見ていますか?テストは失敗しましたが、テストは失敗しました。

enter image description here

答えて

3

それが解決する約束を待っていないので、テストはその通過を示して - あなたはit機能に約束を返す必要があります:

it('should have users',() => { 

    afterEach(() => { 
     nock.cleanAll() 
    }) 

    return CrudApi.getAll().then(
     data => {expect(data).toHaveLength(9) // this failed 
     console.log(data.length) // 10} 
    ) 
}); 
関連する問題