2017-11-16 4 views
0

을 수정하십시오. 여기에 설명 된 것과 동일한 문제입니다 : https://github.com/facebook/jest/issues/2980. done()은 오류로 인해 호출되지 않으므로 jamsin 시간 초과에 도달했습니다. 괜찮아. 하지만 재 스민/농담이 그 일이 일어난 오류를보고해야한다는 것은 좋지 않습니다.jest : Promise에서 오류 메시지가 표시됩니다.

참고 : 예제 소스 코드는 here입니다. 그래서 오류가 을해야의 xxx 변수가 정의되지 않습니다

Promise을 만들고 다음 함수를 고려하고, 약속 해결하는 done 콜백 호출합니다

// file: foo.js 

function foo(done) { 
    const p = new Promise((resolve, reject) => { 
     setTimeout(() => { 
      //const xxx = 2; 
      resolve(xxx); 
     }, 100); 
    }); 
    p.then(data => { 
     console.log(data); 
     done() 
    }) 
} 

exports.foo = foo; 

그것은 오류가 있습니다를 높인.

나는 수입이 기능을 실행하고 스크립트를 실행하면 :

// file: index.js 

const foo = require('./foo').foo; 

foo(() => {}); 

node v8.6.0으로 스크립트 실행

node index.js 

내가 ( ReferenceError: xxx is not defined)을 예상 오류 :

/home/dfroger/repo/dfroger/issue/jest-promise-error/foo.js:5 
      resolve(xxx); 
        ^

ReferenceError: xxx is not defined 
    at Timeout.setTimeout [as _onTimeout] (/home/dfroger/repo/dfroger/issue/jest-promise-error/foo.js:5:21) 
    at ontimeout (timers.js:469:11) 
    at tryOnTimeout (timers.js:304:5) 
    at Timer.listOnTimeout (timers.js:264:5) 

지금은에 대한 단위 테스트를 작성합니다. 10 :

// file: foo.test.js 

const foo = require('./foo').foo 

describe('async',() => { 
    it('run foo', done => { 
     foo(done); 
    }); 
}); 

그리고 jest v21.2.1 그것을 실행하지 :

./node_modules/.bin/jest 

나는 더 많은 오류 메시지에 대한 xxx being not defined받을 번호 :

async 
    ✕ run foo (5004ms) 

    ● async › run foo 

    Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. 

     at node_modules/jest-jasmine2/build/queue_runner.js:64:21 
     at ontimeout (timers.js:469:11) 
     at tryOnTimeout (timers.js:304:5) 
     at Timer.listOnTimeout (timers.js:264:5) 

Test Suites: 1 failed, 1 total 
Tests:  1 failed, 1 total 
Snapshots: 0 total 
Time:  5.574s, estimated 6s 
Ran all test suites. 

내가 놓친 건가은 jest를 사용? 버그 jest입니까? jest 이 항상 오류 메시지를 올바르게보고하는지 어떻게 확인할 수 있습니까?

답변

0

약속에 캐치 블록을 추가하지 않았습니다. 비록 내가 그것을 전부 시험 할 수는 없지만, 나는 이것이 당신의 문제라고 믿습니다;

// 파일 :

function foo(done) { 
    const p = new Promise((resolve, reject) => { 
     setTimeout(() => { 
      //const xxx = 2; 
      resolve(xxx); 
     }, 100); 
    }); 
    p.then(data => { 
     console.log(data); 
     done() 
    }) 
    .catch(err => { 
     console.log(`Following error occured : ${err}`); 
    });  
} 

exports.foo = foo; 
foo.js
관련 문제