Skip to content

Can't run it.each or test.each in fakeAsync zone #339

Closed
@andrewalderson

Description

I ran into an issue with not being able to run it.each or test.each in a fakeAsync zone. This sample test

  it.each([[1]])('should be equal', fakeAsync((val) => {
    expect(val).toEqual(val);
  }));

results in the following error

  Expected to be running in 'ProxyZone', but it was not found.

      at Function.Object.<anonymous>.ProxyZoneSpec.assertPresent (../node_modules/zone.js/dist/proxy.js:42:19)

After some investigation it turns out that describe.each does work so as a test I modified the zone-patch file by adding

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

and then changing line 96 from

env[methodName].each = originaljestFn.each;

to

env[methodName].each = bindTest(originaljestFn.each);

This fixed the issue.

I am a little confused as to why the describe blocks were patched but the other blocks weren't. Was there a reason?
I could submit a pull request for this once I understand if this is the correct fix.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions