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.

Compat issue with jasmine 2.0.0 regarding currentSpec.queue.running #5632

Closed

Description

@johnpapa

Angular Mocks checks if a spec is running by using

 // Line 1922
 isSpecRunning = function() {
     return currentSpec && (window.mocha || currentSpec.queue.running);
 };

 beforeEach(function() {
   currentSpec = this;
 });

However in Jasmine 2.0.0 currentSpec.queue doesn;t exist nor does any "running" property. How do we determine if a spec is running so we can propose a pull request for NG mocks?

See ... jasmine/jasmine#492

Activity

  1. johnpapa commented on Jan 4, 2014

    @johnpapa
    ContributorAuthor

    What I did in the meantime to get the tests to run is ...

    // line 1922-1924
    isSpecRunning = function () {
        return !!currentSpec; // && (window.mocha || currentSpec.queue.running);
    };
    

    And then ...

    // line 1978
    return isSpecRunning() ? workFn() || workFn : workFn;
    

    It's a hack so I'd love to hear some better options

  2. IgorMinar commented on Jan 5, 2014

    @IgorMinar
    Contributor

    Some background for what the code does (if it's not obvious): the reason for this check is that inject and module helper functions are implemented in different ways depending on whether the spec is running or not.

    If a spec is not running we need set up the spec so that when jasmine executes it, the injector will inject the nested spec fn. In this case inject is asynchronous:

    it('should do something', inject(function(someService) {
    }));
    

    however if you use inject from within a spec, the injection must be synchronous. This is commonly used if you need both the module helper and inject helper in the same spec.

    it('should do something', function() {
      module(function(someProvider) {
      });
      inject(function(someService) {
      });
    });
    
  3. IgorMinar commented on Jan 5, 2014

    @IgorMinar
    Contributor

    this really is a jasmine issue, so I'm eagerly waiting for some reply to jasmine/jasmine#492

  4. johnpapa commented on Jan 5, 2014

    @johnpapa
    ContributorAuthor

    @IgorMinar Their response seems reasonable and something that you could modify angular mocks with. Would the simple hack I did work or their reporter option work?

  5. johnpapa commented on Jan 7, 2014

    @johnpapa
    ContributorAuthor

    The related issue was closed with Jasmine, and I agree with them that it should be a change in Angular Mocks (after reading their reasoning). I've modified my angular mocks to use the modified code to make this work again and its going well. I request that this change be made to angular mocks too.

    isSpecRunning = function () { 
      return !!currentSpec; 
    };
    

    because the window.mocha || window.jasmine check seems to have been done on line 1917.

    An alternate option, perhaps for users that don't want to add their own beforeEach/afterEach for spec tracking, is to use the Jasmine reporter interface. Adopted for the angular-mock use case, that would look something like the following:

    isSpecRunning = (function() { // assumes this function is still guarded by 'if(window.jasmine || window.mocha) {'
      if (window.jasmine) {
        var specRunning = false;
        window.jasmine.getEnv().addReporter({
          specStarted: function() { specRunning = true; },
          specDone: function() { specRunning = false; }
        });
        return function() { return specRunning; };
      } else {
        return function() { return !!currentSpec; };
      }
    })();
    

    I'll make a pull request.

  6. mbenford commented on Mar 15, 2014

    @mbenford
    Contributor

    Shouldn't this issue be closed?

  7. Narretz commented on Jun 20, 2014

    @Narretz
    Contributor

    indeed, this was fixed in 95f0bf9 @IgorMinar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions