Skip to content

fix(src/resolve): use injector's strictDi value in calls to .annotate #2602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/resolve/resolvable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ import {ResolveContext} from "./resolveContext";
*/
export class Resolvable {
constructor(name: string, resolveFn: Function, preResolvedData?: any) {
extend(this, { name, resolveFn, deps: services.$injector.annotate(resolveFn), data: preResolvedData });
extend(this, {
name,
resolveFn,
deps: services.$injector.annotate(resolveFn, services.$injector.strictDi),
data: preResolvedData
});
}

name: string;
Expand Down
2 changes: 1 addition & 1 deletion src/resolve/resolveContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class ResolveContext {

/** Inspects a function `fn` for its dependencies. Returns an object containing any matching Resolvables */
getResolvablesForFn(fn: IInjectable): { [key: string]: Resolvable } {
let deps = services.$injector.annotate(<Function> fn);
let deps = services.$injector.annotate(<Function> fn, services.$injector.strictDi);
return <any> pick(this.getResolvables(), deps);
}

Expand Down
45 changes: 44 additions & 1 deletion test/resolveSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ beforeEach(function () {
O: { resolve: { _O: function(_O2) { return _O2 + "O"; }, _O2: function(_O) { return _O + "O2"; } } },
P: { resolve: { $state: function($state) { return $state } },
Q: { resolve: { _Q: function($state) { counts._Q++; vals._Q = $state; return "foo"; }}}
}
},
PAnnotated: { resolve: { $state: ['$state', function($state) { return $state }] } }
};

var stateProps = ["resolve", "resolvePolicy"];
Expand Down Expand Up @@ -95,6 +96,48 @@ describe('Resolvables system:', function () {
asyncCount = 0;
}));

describe('strictDi support', function () {
let originalStrictDi: boolean;
let supportsStrictDi = false;

beforeEach(inject(function ($injector) {
// not all angular versions support strictDi mode.
// here, we detect the feature
try {
$injector.annotate(() => {}, true);
} catch (e) {
supportsStrictDi = true;
}

if (supportsStrictDi) {
originalStrictDi = $injector.strictDi;
$injector.strictDi = true;
}
}));

afterEach(inject(function ($injector) {
if (supportsStrictDi) {
$injector.strictDi = originalStrictDi;
}
}));

it('should throw when creating a resolvable with an unannotated fn and strictDi mode on', inject(function ($injector) {
if (supportsStrictDi) {
expect(() => {
makePath([ "P" ]);
}).toThrowError(/strictdi/);
}
});

it('should not throw when creating a resolvable with an annotated fn and strictDi mode on', inject(function ($injector) {
if (supportsStrictDi) {
expect(() => {
makePath([ "PAnnotated" ]);
}).not.toThrowError(/strictdi/);
}
});
});

describe('ResolveContext.resolvePathElement()', function () {
it('should resolve all resolves in a PathElement', inject(function ($q) {
let path = makePath([ "A" ]);
Expand Down