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

Commit bbe0a9c

Browse files
committed
Added mocha support to angular mocks
1 parent 54e4a6f commit bbe0a9c

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

src/ngMock/angular-mocks.js

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,22 +1587,49 @@ window.jstestdriver && (function(window) {
15871587
})(window);
15881588

15891589

1590-
window.jasmine && (function(window) {
1590+
(window.jasmine || window.mocha) && (function(window) {
15911591

1592-
afterEach(function() {
1593-
var spec = getCurrentSpec();
1594-
spec.$injector = null;
1595-
spec.$modules = null;
1596-
angular.mock.clearDataCache();
1597-
});
1592+
if (window.jasmine) {
1593+
afterEach(function() {
1594+
var spec = getCurrentSpec();
1595+
spec.$injector = null;
1596+
spec.$modules = null;
1597+
angular.mock.clearDataCache();
1598+
});
1599+
1600+
function getCurrentSpec() {
1601+
return jasmine.getEnv().currentSpec;
1602+
}
15981603

1599-
function getCurrentSpec() {
1600-
return jasmine.getEnv().currentSpec;
1604+
function isSpecRunning() {
1605+
var spec = getCurrentSpec();
1606+
return spec && spec.queue.running;
1607+
}
16011608
}
16021609

1603-
function isSpecRunning() {
1604-
var spec = getCurrentSpec();
1605-
return spec && spec.queue.running;
1610+
if (window.mocha) {
1611+
var currentSpec;
1612+
1613+
beforeEach(function() {
1614+
currentSpec = this;
1615+
});
1616+
1617+
afterEach(function() {
1618+
var spec = getCurrentSpec();
1619+
this.$injector = null;
1620+
this.$modules = null;
1621+
angular.mock.clearDataCache();
1622+
1623+
currentSpec = null;
1624+
});
1625+
1626+
function getCurrentSpec() {
1627+
return currentSpec;
1628+
}
1629+
1630+
function isSpecRunning() {
1631+
return getCurrentSpec();
1632+
}
16061633
}
16071634

16081635
/**

0 commit comments

Comments
 (0)