Skip to content

Commit

Permalink
optional deps setter test
Browse files Browse the repository at this point in the history
  • Loading branch information
rashtao committed Sep 29, 2015
1 parent 61ad1df commit 4f53d16
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
9 changes: 9 additions & 0 deletions tests/injectables/optional_setter/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_setter/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;
12 changes: 12 additions & 0 deletions tests/injectables/optional_setter/singleton/service3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var MyService = function () {
this.name = "singleton/service3";
};

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

exports['@singleton'] = true;
exports['@require'] = ['service1'];
exports['@optional'] = ['missingDep', 'service2'];
exports['@type'] = 'setterInjection';
2 changes: 0 additions & 2 deletions tests/optionalDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ before(function () {
});

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")());
Expand All @@ -23,7 +22,6 @@ describe('optionalDeps', function () {
expect(IoC.create("singleton/service3").service2).to.equal(IoC.create("singleton/service2"));
});


});


27 changes: 27 additions & 0 deletions tests/optionalDeps_setter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
delete require.cache[require.resolve('electrolyte')];
var IoC = require('electrolyte');

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

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

describe('optionalDeps_setter', function () {

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

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

});


0 comments on commit 4f53d16

Please sign in to comment.