npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hydrajs-testing-helper

v1.5.3

Published

Hydra.js testing helper tools to improve testability of modules.

Downloads

378

Readme

hydrajs-testing-helper

Is a testing extension helper that add some helper methods to make easy test all Hydra modules.

Updated to version 1.5.3

Build Status

Changelog

Install

Install with Bower

bower install hydrajs-testing-helper

Install with Component

component install hydrajs-testing-helper

Install with NPM

npm install hydrajs-testing-helper

Use in browser

Insert in your html code:

<script type="text/javascript" src="hydra.js"></script
<script type="text/javascript" src="hydrajs-testing-helper.js"></script>

Use with requirejs

Insert in your code:

define(['hydrajs-testing-helper'], function () {
// code here.
});

Common usage

hydrajs-testing-helper extends Hydra.js library adding new methods.

Hydra.setTestFramework

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 );

Hydra.module.getModule

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;
});

Hydra.module.decorate

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.
});

Hydra.module.extend

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.
});

Hydra.module.test

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:

How to mock dependencies

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.

API

Hydra

setTestFramework - Params [Object - framework test]

This method expects an object [Jasmine, jstestdriver...]

Hydra.module

getModule - Params [String - identifier of Module, String - identifier of Instance]

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]

test - Params [String - identifier of Module, [Function, Object or Array]]

Tip: You can see how it can be used in the Hydra's test file

License

hydrajs-testing-helper is licensed under MIT license. (see LICENSE file)