Is a testing extension helper that add some helper methods to make easy test all Hydra modules.
Install with Bower
bower install hydrajs-testing-helper
Install with Component
component install hydrajs-testing-helper
Install with NPM
npm install hydrajs-testing-helper
Insert in your html code:
<script type="text/javascript" src="hydra.js"></script
<script type="text/javascript" src="hydrajs-testing-helper.js"></script>
Insert in your code:
define(['hydrajs-testing-helper'], function () {
// code here.
});
hydrajs-testing-helper extends Hydra.js library adding new methods.
This method is needed to set which test framework we will use. If the test framework is not set the other methods will not work.
Hydra.setTestFramework( oTestFramework );
This method returns a instance of the module is useful to use it when you want a module to be accessible in your tests.
Hydra.module.getModule( sModuleId, sIdInstance, function( oMod ) {
oModule = oMod;
});
This method wrap the original decorate method of Hydra to resolve the dependencies in decorated modules.
// aDependencies is optional
Hydra.module.decorate( sBaseModuleId, sExtendedModuleId, aDependencies, function() {
// Your module code here.
});
This method wrap the original extend method of Hydra to resolve the dependencies in extended modules.
// aDependencies is optional
Hydra.module.decorate( sBaseModuleId, sExtendedModuleId, aDependencies, function() {
// Your module code here.
});
This method returns a module that will not wrap any method allowing you to test it and get the errors.
With callback:
var oModule = null;
Hydra.module.test( 'moduleId', function(oMod) {
oModule = oMod;
});
Without callback:
var oModule = Hydra.module.test( 'moduleId' );
This method allow you to mock all your dependencies defined when the module is registered:
Automatic:
var oModule = Hydra.module.test( sModuleId );
Using only the id of the module, the method will check for the dependencies defined when the module was registered and it will resolve them but returning the objects after being mocked.
Using an array:
var oModule = Hydra.module.test( sModuleId, [ dependency1, dependency2 ]);
You should add an array with the mocked objects in the same order that were defined when the module was registered.
Using an object:
var oModule = Hydra.module.test( sModuleId, { dep1: dependency1, dep2: dependency2 });
You should add an object with the mocked objects and the keys should be the same that were defined when the module was registered.
This method expects an object [Jasmine, jstestdriver...]
decorate - Params [String - identifier of Base Module, String - identifier of Decorated module, [Function or Array]
extend - Params [String - identifier of Base Module, String - identifier of Decorated module, [Function or Array]
Tip: You can see how it can be used in the Hydra's test file
hydrajs-testing-helper is licensed under MIT license. (see LICENSE file)