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

Commit

Permalink
fix(mocks): always call functions injected with inject with this
Browse files Browse the repository at this point in the history
…set to the current spec

Currently when a function is injected inside of a test we set the context to undefined which
is a bug.

Closes #6102
  • Loading branch information
wesalvaro authored and IgorMinar committed Feb 4, 2014
1 parent e7ac7aa commit 3bf4390
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ngMock/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,7 @@ if(window.jasmine || window.mocha) {
window.inject = angular.mock.inject = function() {
var blockFns = Array.prototype.slice.call(arguments, 0);
var errorForStack = new Error('Declaration Location');
return isSpecRunning() ? workFn() : workFn;
return isSpecRunning() ? workFn.call(currentSpec) : workFn;
/////////////////////
function workFn() {
var modules = currentSpec.$modules || [];
Expand Down
19 changes: 19 additions & 0 deletions test/ngMock/angular-mocksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,25 @@ describe('ngMock', function() {
});


describe('this', function() {

it('should set `this` to be the jasmine context', inject(function() {
expect(this instanceof jasmine.Spec).toBe(true);
}));

it('should set `this` to be the jasmine context when inlined in a test', function() {
var tested = false;

inject(function() {
expect(this instanceof jasmine.Spec).toBe(true);
tested = true;
});

expect(tested).toBe(true);
});
});


// We don't run the following tests on IE8.
// IE8 throws "Object does not support this property or method." error,
// when thrown from a function defined on window (which `inject` is).
Expand Down

0 comments on commit 3bf4390

Please sign in to comment.