{"size": 2083, "ext": "js", "max_stars_repo_path": "test/factories/objects.spec.js", "max_stars_repo_name": "allenevans/essencejs", "max_stars_repo_stars_event_min_datetime": "2015-01-02T19:48:42.000Z", "max_stars_repo_stars_event_max_datetime": "2015-01-20T13:53:51.000Z", "max_issues_repo_path": "test/factories/objects.spec.js", "max_issues_repo_name": "allenevans/essencejs", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/factories/objects.spec.js", "max_forks_repo_name": "allenevans/essencejs", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.5606060606, "max_line_length": 111, "alphanum_fraction": 0.5079212674}
/*
 * File         :   objects.spec.js
 * Description  :   TEST register objects as factories.
 * ------------------------------------------------------------------------------------------------ */
"use strict";

var path = require("path"),
    essencejs;

module.exports = {
    setUp : function (callback) {
        essencejs = new (require(process.cwd()).EssenceJs)();
        callback();
    },
    tearDown : function(callback) {
        essencejs.dispose();
        callback();
    },
    "When object is registered as a factory then a cloned copy of the object should be returned when injected":
        function (test) {
            test.expect(4);

            var origMyObject = {
                now : new Date(),
                name : "this is my object"
            };

            essencejs.factory("myObject", origMyObject);

            essencejs.inject(function (myObject) {
                test.equal(!!myObject, true);
                test.equal(myObject.name, origMyObject.name);

                test.notEqual(myObject.now, origMyObject.now);
                test.notEqual(myObject, origMyObject);

                test.done();
            });
        },
    "Register class instance as a factory":
        function (test) {
            test.expect(5);

            var MyClass = function MyClass(params) {
                this.value = (params && params.value) || null;
            };

            MyClass.prototype.getValue = function getValue() {
                return this.value;
            };

            var origMyClassInstance = new MyClass({ value : "abc" });

            essencejs.factory("myClass", origMyClassInstance);

            essencejs.inject(function (myClass) {
                test.equal(!!myClass, true);
                test.equal(myClass.value, origMyClassInstance.value);
                test.equal(myClass.getValue(), origMyClassInstance.getValue());
                test.equal(myClass instanceof MyClass, true);
                test.notEqual(myClass, origMyClassInstance);

                test.done();
            });
        }
};