{"size": 1513, "ext": "js", "max_stars_repo_path": "test/unit/factory/decorator.js", "max_stars_repo_name": "gobwas/dm.js", "max_stars_repo_stars_event_min_datetime": "2015-01-08T09:09:27.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-12T23:37:14.000Z", "max_issues_repo_path": "test/unit/factory/decorator.js", "max_issues_repo_name": "gobwas/dm.js", "max_issues_repo_issues_event_min_datetime": "2015-02-13T13:30:06.000Z", "max_issues_repo_issues_event_max_datetime": "2016-07-13T08:44:39.000Z", "max_forks_repo_path": "test/unit/factory/decorator.js", "max_forks_repo_name": "gobwas/dm.js", "max_forks_repo_forks_event_min_datetime": "2015-03-30T10:08:29.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-25T15:59:40.000Z"}
{"max_stars_count": 41, "max_issues_count": 29, "max_forks_count": 8, "avg_line_length": 28.0185185185, "max_line_length": 83, "alphanum_fraction": 0.5333773959}
var DecoratorFactory = require("../../../lib/factory/decorator");
var Factory = require("../../../lib/factory");
var expect = require("chai").expect;
var sinon  = require("sinon");
var _      = require("lodash");
var chance = require("chance");

describe("DecoratorFactory", function() {

    describe("#constructor", function() {

        it("should throw error when no given factory", function() {
            // when
            function create() {
                new DecoratorFactory({});
            }

            // then
            expect(create).to.throw(TypeError, "Factory is expected");
        });

    });

    describe("#factory", function() {
        var instance, inner;

        beforeEach(function() {
            inner = Object.create(Factory.prototype);
            instance = new DecoratorFactory({}, inner);
        });

        it("should call inner factory on call", function() {
            var definition, response, factoryStub, result;

            // before
            definition = {};
            response = {};
            factoryStub = sinon.stub(inner, "factory", function() {
                return response;
            });

            // when
            result = instance.factory(definition);
            expect(result).to.be.a("function");

            // now call
            expect(result()).equal(response);
            expect(factoryStub.callCount).equal(1);
            expect(factoryStub.firstCall.calledWithExactly(definition)).to.be.true;
        });

    });

});