[英]Will a beforeEach that is outside a describe always complete before the start of a beforeEach that is inside a describe?
Is the outer beforeEach
guaranteed to complete before the inner beforeEach
starts? 是否beforeEach
保证外部的beforeEach
在内部的beforeEach
开始之前完成?
let qux;
beforeEach(() => {
//
// other synchronous code here
//
qux = null;
});
describe('Description', () => {
beforeEach(() => {
qux = 0;
//
// other synchronous code here
//
});
it('Predicate', () => {
expect(qux).toEqual(0);
});
});
In other words, is the above test guaranteed to pass? 换句话说,上述测试是否可以通过?
Yes, the outer beforeEach
is guaranteed to complete before the inner beforeEach
starts: 是的,保证外部的beforeEach
在内部的beforeEach
开始之前完成:
Jest
finds all the before
functions for a spec by starting where the spec is defined and walking up the parents here and returning the reversed list here . Jest
通过从定义规范的位置开始并在此处向上移动父级,然后在此处返回反向列表, 找到该规范的所有before
函数。
The before
functions, test, and after
functions get put in an array here . 将before
函数,test和after
函数放在此处的数组中。
Each function is wrapped by mapper
which returns a Promise that does not resolve until the function completes, the test is cancelled, an error occurs, or the timeout is reached , and the resulting Promises are chained together by the reduce
here . 每个函数都由mapper
包装,该mapper
返回一个Promise, 直到该函数完成,取消测试,发生错误或达到超时 ,并且在此处的reduce
链接在一起的Promise 才解决 。
So unless there is an error, a timeout, or the test is cancelled the beforeEach
functions will run to completion in order and the test above will pass. 因此,除非出现错误,超时或测试被取消, beforeEach
函数将按顺序运行至完成,并且上述测试将通过。
PR中有一些信息,它增加了对多个beforeEach / afterEach调用的支持( https://github.com/qunitjs/qunit/pull/1188/files)-只要您的操作是同步的,就可以了-您也可以在上述PR的测试案例中进行验证。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.