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:
Peter Pisljar 2016-09-21 21:23:34 +02:00 committed by GitHub
commit bde2591501

View file

@ -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
}); });
} }