Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Running angular-mocks tests concurrently #13971

Closed
@karlhorky

Description

@karlhorky

I've been playing around with testing Angular directives in the AVA concurrent test runner and I've run into issues with getting the tests running concurrently. It appears angular-mocks rewrites variables in the afterEach() method, causing property reference errors:

Partial test setup

import test from 'ava';

// ...

global.window.beforeEach = test.beforeEach;
global.window.afterEach = test.afterEach;
require('angular-mocks');

// ...

test('a', t => t.true(true));
test('b', t => t.true(true));

Command line output (annotated with comment lines)

$ ava --verbose

# beforeEach for "a" called
# beforeEach for "b" called
  ✔ a
  ✔ b
# afterEach for "a" called  <-- currentSpec set to null here
  ✖ afterEach for "b" failed with "Cannot read property '$injector' of null"

  1 test failed

  1. afterEach for "b"
  TypeError: Cannot read property '$injector' of null
    Test.fn (node_modules/angular-mocks/angular-mocks.js:2593:31)

Relevant code from angular-mocks

  (window.beforeEach || window.setup)(function() {
    // ...
    currentSpec = this;
  });

  (window.afterEach || window.teardown)(function() {
    var injector = currentSpec.$injector;

    // ...

    currentSpec.$injector = null;
    currentSpec.$modules = null;
    currentSpec.$providerInjector = null;
    currentSpec = null;

    // ...

  });

Rewriting the tests to execute serially works around this error (but loses the nice property of concurrency):

test.serial('a', t => t.true(true));
test.serial('b', t => t.true(true));

A full example including failing and working cases here:
https://gist.github.com/karlhorky/6e68101d8167be27e027

Is concurrent tests something that the angular team is interested in supporting? If not, are there any other workarounds for getting angular-mocks running concurrently?

angular.js v. 1.5.0
angular-mocks v. 1.5.0

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions