Skip to content

Commit

Permalink
fix: test.each should be in ProxyZone
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion committed Jan 8, 2020
1 parent c05c122 commit 7a41424
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/zone-patch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ const bindDescribe = originalJestFn =>
};
};

const bindTest = originalJestFn =>
function() {
const eachArguments = arguments;
return function(description, specDefinitions, timeout) {
arguments[1] = wrapTestInZone(specDefinitions);
return originalJestFn.apply(this, eachArguments).apply(this, arguments);
};
};

['xdescribe', 'fdescribe', 'describe'].forEach(methodName => {
const originaljestFn = env[methodName];
env[methodName] = function(description, specDefinitions, timeout) {
Expand All @@ -72,8 +81,6 @@ const bindDescribe = originalJestFn =>
if (methodName === 'describe') {
env[methodName].only = env['fdescribe'];
env[methodName].skip = env['xdescribe'];
env[methodName].only.each = bindDescribe(originaljestFn.only.each);
env[methodName].skip.each = bindDescribe(originaljestFn.skip.each);
}
});

Expand All @@ -83,17 +90,13 @@ const bindDescribe = originalJestFn =>
arguments[1] = wrapTestInZone(specDefinitions);
return originaljestFn.apply(this, arguments);
};
// The revised method will be populated to the final each method, so we only declare the method that in the new globals
env[methodName].each = originaljestFn.each;
env[methodName].each = bindTest(originaljestFn.each);

if (methodName === 'test' || methodName === 'it') {
env[methodName].only = env['fit'];
env[methodName].only.each = originaljestFn.only.each;

env[methodName].skip = env['xit'];
env[methodName].skip.each = originaljestFn.skip.each;

env[methodName].todo = function(description) {
env[methodName].todo = function() {
return originaljestFn.todo.apply(this, arguments);
};
}
Expand Down

0 comments on commit 7a41424

Please sign in to comment.