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

Commit 92558fe

Browse files
camwestmhevery
authored andcommitted
feat(mocha): support mocha in angular mocks
1 parent d519953 commit 92558fe

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/ngMock/angular-mocks.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -1587,14 +1587,20 @@ window.jstestdriver && (function(window) {
15871587
})(window);
15881588

15891589

1590-
window.jasmine && (function(window) {
1590+
(window.jasmine || window.mocha) && (function(window) {
1591+
1592+
var currentSpec = null;
1593+
1594+
beforeEach(function() {
1595+
currentSpec = this;
1596+
});
15911597

15921598
afterEach(function() {
1593-
var spec = getCurrentSpec();
1594-
var injector = spec.$injector;
1599+
var injector = currentSpec.$injector;
15951600

1596-
spec.$injector = null;
1597-
spec.$modules = null;
1601+
currentSpec.$injector = null;
1602+
currentSpec.$modules = null;
1603+
currentSpec = null;
15981604

15991605
if (injector) {
16001606
injector.get('$rootElement').unbind();
@@ -1616,13 +1622,8 @@ window.jasmine && (function(window) {
16161622
angular.callbacks.counter = 0;
16171623
});
16181624

1619-
function getCurrentSpec() {
1620-
return jasmine.getEnv().currentSpec;
1621-
}
1622-
16231625
function isSpecRunning() {
1624-
var spec = getCurrentSpec();
1625-
return spec && spec.queue.running;
1626+
return currentSpec && currentSpec.queue.running;
16261627
}
16271628

16281629
/**
@@ -1647,11 +1648,10 @@ window.jasmine && (function(window) {
16471648
return isSpecRunning() ? workFn() : workFn;
16481649
/////////////////////
16491650
function workFn() {
1650-
var spec = getCurrentSpec();
1651-
if (spec.$injector) {
1651+
if (currentSpec.$injector) {
16521652
throw Error('Injector already created, can not register a module!');
16531653
} else {
1654-
var modules = spec.$modules || (spec.$modules = []);
1654+
var modules = currentSpec.$modules || (currentSpec.$modules = []);
16551655
angular.forEach(moduleFns, function(module) {
16561656
modules.push(module);
16571657
});
@@ -1718,13 +1718,13 @@ window.jasmine && (function(window) {
17181718
return isSpecRunning() ? workFn() : workFn;
17191719
/////////////////////
17201720
function workFn() {
1721-
var spec = getCurrentSpec();
1722-
var modules = spec.$modules || [];
1721+
var modules = currentSpec.$modules || [];
1722+
17231723
modules.unshift('ngMock');
17241724
modules.unshift('ng');
1725-
var injector = spec.$injector;
1725+
var injector = currentSpec.$injector;
17261726
if (!injector) {
1727-
injector = spec.$injector = angular.injector(modules);
1727+
injector = currentSpec.$injector = angular.injector(modules);
17281728
}
17291729
for(var i = 0, ii = blockFns.length; i < ii; i++) {
17301730
try {

0 commit comments

Comments
 (0)