Skip to content
This repository has been 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
johnpapa opened this issue Jan 4, 2014 · 7 comments
Closed

Comments

@johnpapa
Copy link
Contributor

johnpapa commented Jan 4, 2014

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

@johnpapa
Copy link
Contributor Author

johnpapa commented Jan 4, 2014

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

@IgorMinar
Copy link
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) {
  });
});

@IgorMinar
Copy link
Contributor

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

@johnpapa
Copy link
Contributor Author

johnpapa commented Jan 5, 2014

@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?

@johnpapa
Copy link
Contributor Author

johnpapa commented Jan 7, 2014

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.

@mbenford
Copy link
Contributor

Shouldn't this issue be closed?

@Narretz
Copy link
Contributor

Narretz commented Jun 20, 2014

indeed, this was fixed in 95f0bf9 @IgorMinar

jocelynalsdorf added a commit to jocelynalsdorf/angular-alien-project1 that referenced this issue Oct 10, 2015
…ar-mocks/jasmine per angular/angular.js#5632 comments; first karma test now passing
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants