mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 10:23:14 -04:00
Merge pull request #8396 from ppisljar/fix/mochaDescribeOnly
fixing top_level_describe_filter to allow describe.only in unit tests
This commit is contained in:
commit
bde2591501
1 changed files with 29 additions and 22 deletions
|
@ -67,11 +67,7 @@ export function setupTopLevelDescribeFilter(test) {
|
||||||
let describeCallDepth = 0;
|
let describeCallDepth = 0;
|
||||||
const ignoredCalls = [];
|
const ignoredCalls = [];
|
||||||
|
|
||||||
// ensure that window.describe isn't messed with by other code
|
const describeInterceptor = function (describeName, describeBody) {
|
||||||
Object.defineProperty(window, 'describe', {
|
|
||||||
configurable: false,
|
|
||||||
enumerable: true,
|
|
||||||
value: function describeInterceptor(describeName, describeBody) {
|
|
||||||
const context = this;
|
const context = this;
|
||||||
|
|
||||||
const isTopLevelCall = describeCallDepth === 0;
|
const isTopLevelCall = describeCallDepth === 0;
|
||||||
|
@ -86,12 +82,23 @@ export function setupTopLevelDescribeFilter(test) {
|
||||||
* note that try/finally won't actually catch the error, it
|
* note that try/finally won't actually catch the error, it
|
||||||
* will continue to propogate up the call stack
|
* will continue to propogate up the call stack
|
||||||
*/
|
*/
|
||||||
|
let result;
|
||||||
try {
|
try {
|
||||||
describeCallDepth += 1;
|
describeCallDepth += 1;
|
||||||
originalDescribe.call(context, describeName, describeBody);
|
result = originalDescribe.call(context, describeName, describeBody);
|
||||||
} finally {
|
} finally {
|
||||||
describeCallDepth -= 1;
|
describeCallDepth -= 1;
|
||||||
}
|
}
|
||||||
}
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
// to allow describe.only calls. we dont need interceptor as it will call describe internally
|
||||||
|
describeInterceptor.only = originalDescribe.only;
|
||||||
|
|
||||||
|
// ensure that window.describe isn't messed with by other code
|
||||||
|
Object.defineProperty(window, 'describe', {
|
||||||
|
configurable: false,
|
||||||
|
enumerable: true,
|
||||||
|
value: describeInterceptor
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue