Skip to content

Commit

Permalink
optional deps test
Browse files Browse the repository at this point in the history
  • Loading branch information
rashtao committed Sep 29, 2015
1 parent 6c4ebcc commit 61ad1df
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/injectables/optional/singleton/service1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var MyService = function () {
this.name = "singleton/service1";
};

exports = module.exports = function () {
return new MyService();
};

exports['@singleton'] = true;
9 changes: 9 additions & 0 deletions tests/injectables/optional/singleton/service2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var MyService = function () {
this.name = "singleton/service2";
};

exports = module.exports = function () {
return new MyService();
};

exports['@singleton'] = true;
14 changes: 14 additions & 0 deletions tests/injectables/optional/singleton/service3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var MyService = function (service1, missingDep, service2) {
this.service1 = service1;
this.missingDep = missingDep;
this.service2 = service2;
this.name = "singleton/service3";
};

exports = module.exports = function (service1, missingDep, service2) {
return new MyService(service1, missingDep, service2);
};

exports['@singleton'] = true;
exports['@require'] = ['singleton/service1'];
exports['@optional'] = ['missingDep', 'singleton/service2'];
29 changes: 29 additions & 0 deletions tests/optionalDeps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
delete require.cache[require.resolve('electrolyte')];
var IoC = require('electrolyte');

var expect = require('chai').expect;

before(function () {
IoC.singleton("singleton/service1", require("./injectables/optional/singleton/service1"));
IoC.singleton("singleton/service2", require("./injectables/optional/singleton/service2"));
IoC.singleton("singleton/service3", require("./injectables/optional/singleton/service3"));
});

describe('optionalDeps', function () {
// TODO: implement chacks on all the fields

it('injectedEquality', function () {
expect(IoC.create("singleton/service3").service1).to.eql(require("./injectables/optional/singleton/service1")());
expect(IoC.create("singleton/service3").service2).to.eql(require("./injectables/optional/singleton/service2")());
expect(IoC.create("singleton/service3").missingDep).to.be.null;
});

it('injectedIdentity', function () {
expect(IoC.create("singleton/service3").service1).to.equal(IoC.create("singleton/service1"));
expect(IoC.create("singleton/service3").service2).to.equal(IoC.create("singleton/service2"));
});


});


0 comments on commit 61ad1df

Please sign in to comment.