jsInject Test Suite

Simple tests for JavaScript IoC

by Jeremy Likness

HTML

<script src="http://pivotal.github.io/jasmine/lib/jasmine-1.3.1/jasmine.js"></script>
<link rel="stylesheet" href="http://pivotal.github.io/jasmine/lib/jasmine-1.3.1/jasmine.css">
<script src="http://pivotal.github.io/jasmine/lib/jasmine-1.3.1/jasmine-html.js"></script>
<div class="version"></div>

<h1>jsInject Test Suite</h1>

<p><a href="https://github.com/JeremyLikness/jsInject" target="_blank">https://github.com/JeremyLikness/jsInject</a>

CSS

body {
    font-family: Segoe UI, Arial, Verdana;
}

JavaScript

var WintellectJs;
(function (WintellectJs) {

    'use strict';

    var $$jsInject = (function () {
        function $$jsInject() {
            var _this = this;
            this.maxRecursion = 20;
            this.errorRecursion = "Maximum recursion at ";
            this.errorArray = "Must pass array.";
            this.errorRegistration = "Already registered.";
            this.errorFunction = "Must pass function to invoke.";
            this.errorService = "Service does not exist.";
            this.isArray = function (arr) {
                return Object.prototype.toString.call(arr) === '[object Array]';
            };
            this.invoke = function (fn, deps, instance, level) {
                var i = 0,
                    args = [],
                    lvl = level || 0;
                if (lvl > _this.maxRecursion) {
                    throw _this.errorRecursion + lvl;
                }
                for (; i < deps.length; i += 1) {
                    args.push(_this.get(deps[i], lvl + 1));
                }
                return fn.apply(instance, args);
            };
            this.get = function (name, level) {
                var wrapper = _this.container[name],
                    lvl = level || 0;
                if (wrapper) {
                    return wrapper(lvl);
                }
                throw _this.errorService;
            };
            this.register = function (name, annotatedArray) {
                if (!_this.isArray(annotatedArray)) {
                    throw _this.errorArray;
                }
                if (_this.container[name]) {
                    throw _this.errorRegistration;
                }
                if (typeof annotatedArray[annotatedArray.length - 1] !== 'function') {
                    throw _this.errorFunction;
                }
                _this.container[name] = function (level) {
                    var lvl = level || 0,
                        Template = function () {}, result =...