Open ctrimm opened 8 years ago
Yeah, this would be interesting to figure out – essentially determining whether or not injectables need to be spies or just object literals.
Once we determine how to reliably identify a factory, we could parse properties and give them default values utilizing an approach similar to method parsing.
I imagine the default value could just be the property name:
someFactory.anyProperty = "ANY PROPERTY";
I have a method for reliably distinguishing between properties and methods on an object using dot notation (I do not support bracket notation yet). Issues arise when we have a hybrid object (one with methods and properties) or even a complex object (nested) like in reportService.spec.js:
stateSpy = jasmine.createSpyObj('$state', ['go']); stateSpy.current = { name: 'parent.child.TYPE.group', data: { type: 'TYPE' } };
Complexity begins to balloon and its difficult to decide where to draw the line on how robust our solution should be. The real issue comes down to a branching factor in the boilerplate templates.
I propose we default to creating only the spyObjects in the hybrid case. It will be up to the developer to determine the rest.
Thus, we would only create mock objects for dependencies that have 0 method calls. These would be our factories.
And just as a note so we do not lose track of it... there is a third possibility here: the need to create just a spy. For example, in the case of the formatFilter which is injected but called directly as a function.
Sounds good. And yeah, good point with injectables that are a callable function directly.
Should have a mock object instead of creating a spy for a factory.