【发布时间】:2018-11-30 17:47:26
【问题描述】:
测试用例(Test1, Test2) 在promise 获取数据之前执行。这是文件 mockExecution.js
describe('AC 1: This is suite one', ()=>
{
before((done)=>
{
promiseResp.then((data) => {
console.log("i am in the promise");
responseData = data;
process.exit(0);
}, (err) => {
console.log('promiseResp.err', err);
process.exit(1);
})
done();
})
it('Test1', (done)=>
{
expect(responseData.measure.abc).not.toBe(responseData.measure_list.abc);
done();
});
it('Test2', (done)=>
{
expect(responseData.measure.abc).not.toBe(responseData.measure_list.abc);
done();
});
});
Before 块内的 PromiseResp 不执行。因此“responseData”变量没有数据,它会抛出测试用例失败。我想有一些异步时间问题,但不知道如何解决它,也不知道我把这个“process.exit(0)”放在哪里。下面是实际输出:
AC 1: This is suite one
I am in the before
1) Test1
2) Test2
0 passing (7ms)
2 failing
1) AC 1: This is suite one
Test1:
TypeError: Cannot read property 'measure' of undefined
at Context.it (QA/mockExecution.js:160:29)
2) AC 1: This is suite one
Test2:
TypeError: Cannot read property 'measure' of undefined
at Context.it (QA/mockExecution.js:167:29)
[process business logic and prints some logs here, i can't paste here]
finished analyzing all records
i am in the promise
npm ERR! Test failed. See above for more details.
我希望按以下顺序输出:
[process business logic and prints some logs here, I can't paste here]
finished analyzing all records
AC 1: This is suite one
I am in the before
I am in the promise
1) Test1 passed
2) Test2 paseed
【问题讨论】:
-
你之前为什么要做process.exit?一旦你的承诺真正解决,你就会退出整个测试套件。在这种情况下,这并不重要,因为您错误地运行
it测试之前Promise实际解决。