TJAngular is a small framework that makes writing unit tests a little less painfull. It depends on TypeScript, angular and Jasmine.
Read more on my Website.
Makes unit testing easier by taking care of setting up the environment for you.
"use strict";;@@@@private controller : myprojIStatementDownloadCtrl;@public : void;
Mocking out dependencies in unit tests can be a huge pain. Angular makes testing "easy", but mocking out every dependecy isn't so slick. If you've ever written an Angular unit test (using Jasmine/Mocha), you've probably seen a ton of
beforeEach boilerplate that looks something like this:
In order to test a controller, we have to inject all the dependencies, set up the actual controller and then we can think about the actual test cases.
What if it was a lot easier? What if we could hearness the power of TypeScript and make writing tests fun?
"use strict";;@@@@private controller : myprojIStatementDownloadCtrl;@public : void;@public : voidand;thiscontroller;;
TJAngular does all the
beforeEach boilerplate behind the scenes and just injects the objects that you want to test into your
Instead of writing complicated function
describe constructs as you have known them from Jasmine, you simply write a
TypeScript class for each Test and annotate it properly.
TJAngular holds an internal angular module for all the mocks. You can register mocks by simply annotating them.
;"use strict";@implements serviceIDownloadServicepublic : stringreturn undefined;
TJAnuglar will always first look for a mock to inject them into your requested objects. If there is no mock available, the original injectable will be used.
As shown in the examples above, TJAngular mostly uses
Decorators to do all its magic.
@Spec(classname? : string)- Use it to annotate your test class. You can provide a name, that will be used for the
describe. If no name will be provided, the name of the class will be used.
@FSpec(classname? : string)- Same as above, only that an
fdescribewill be used.
@XSpec(classname? : string)- Same as above, only that an
xdescribewill be used.
@Inject(providerName : string, moduleName : string, dependencies? : Array<string>)- Use it to annotate a property in your class. TJAngular will then inject the requested object into your class, before the
@Beforemethods and the
@Testmethods will be executed. TJAngular will load this dependency from the provided module. Additional modules can be loaded with the
@Mocks(mocks : any)- Use it to provide additional objects/values, that need to be resolved by a resource that was requested with the
@Scope(scope : any)- Use it to provide a scope, that need to be resolved by a resource that was requested with the
@Injectannotation. Internally it will use $rootScope.$new() to create a new scope and extend it with the scope object provided in the annotation. The scope will be injected as $scope into your injectable.
@Template(html : string)- If you want to test directives/components, you need to inject the directive/component using
@Injectand provide a template where the directive/component resides.
@InjectMock(providerName : string)- Same as
@Inject, only that it will load the ressource soely from the internal mock module.
@Test(name? : string)- Use it to annotate a test method. It will use this method and execute it with jasmine's
it. You can provide an optional name. If no name will be provided, the method name will be used as test name.
@FTest(name? : string)- Same as
@Test, only that
fitwill be used.
@XTest(name? : string)- Same as
@Test, only that
xitwill be used.
@Before()- Use it to annotate a method that should be executed after all properties have been injected and before the test methods will be executed.
@ProvideMock(providerName : string, providerType : string)- Use it to annotate classes that you would like to add to the internal mock module.
@ProvideMockService(providerName : string)- Shorthand for
@ProvideMockController(providerName : string)- Shorthand for
@ProvideMockProvider(providerName : string)- Shorthand for
@ProvideMockDirective(providerName : string)- Shorthand for
@ProvideMockConstant(providerName : string)- Shorthand for
@ProvideMockValue(providerName : string)- Shorthand for
Once you have injected a resource into your test class with
@Inject, you can use it in your test methods.
Every injected resource has additional information attached to it, that you can use to test it.
$deps- All dependencies that have been injected into the requested resource. E.g.