-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathdefault-dependency-handler.ts
More file actions
34 lines (29 loc) · 1.16 KB
/
default-dependency-handler.ts
File metadata and controls
34 lines (29 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { ParsedClassDependency, ClassOptions, DependencyHandler, DependencyHandlerOptions } from './model';
import { getUsedMethods } from './helpers';
export default {
run(result: ClassOptions, dep: ParsedClassDependency, options: DependencyHandlerOptions) {
const usedMethods = getUsedMethods(options.sourceCode, dep.name);
result.declarations.push({
name: options.variableName,
type: `jasmine.SpyObj<${dep.type || 'any'}>`
});
if (usedMethods.length > 0) {
result.initializers.push({
name: options.variableName,
value: `jasmine.createSpyObj<${dep.type || 'any'}>(${options.quoteSymbol}${dep.type === 'any' || !dep.type ? dep.name : dep.type}${options.quoteSymbol}, [${usedMethods.map(m => (options.quoteSymbol + m + options.quoteSymbol)).join(`, `)}])`
});
} else {
result.initializers.push({
name: options.variableName,
value: `{} as jasmine.SpyObj<${dep.type || 'any'}>`
});
}
result.dependencies.push({
name: options.variableName,
token: options.injectionToken || 'no-token'
});
},
test(_dep: ParsedClassDependency) {
return true;
}
} as DependencyHandler;