-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for the Binding class
- Loading branch information
Showing
13 changed files
with
241 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Binding } from '../../src/Binding' | ||
|
||
describe('Binding: constructor()', function () { | ||
it('should set default values', function () { | ||
const binding = new Binding() | ||
|
||
this.assert.isNull(binding.getValue()) | ||
this.assert.isNull(binding.getResolver()) | ||
this.assert.isFalse(binding.isFactory()) | ||
}) | ||
|
||
it('should set provided values', function () { | ||
const value = {} | ||
const resolver = () => {} | ||
const isFactory = true | ||
|
||
const binding = new Binding(value, resolver, isFactory) | ||
|
||
this.assert.equal(binding.getValue(), value) | ||
this.assert.equal(binding.getResolver(), resolver) | ||
this.assert.isTrue(binding.isFactory()) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Binding } from '../../src/Binding' | ||
|
||
describe('Binding: getResolver()', function () { | ||
it('should return the resolver', function () { | ||
const resolver = () => {} | ||
const binding = new Binding(null, resolver) | ||
|
||
this.assert.equal(binding.getResolver(), resolver) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Binding } from '../../src/Binding' | ||
|
||
describe('Binding: getValue()', function () { | ||
it('should return the value', function () { | ||
const value = {} | ||
const binding = new Binding(value) | ||
|
||
this.assert.equal(binding.getValue(), value) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Binding } from '../../src/Binding' | ||
|
||
describe('Binding: hasResolved()', function () { | ||
it('should return the hasResolved value', function () { | ||
const binding = new Binding() | ||
|
||
this.assert.isFalse(binding.hasResolved()) | ||
|
||
binding.setHasResolved(true) | ||
|
||
this.assert.isTrue(binding.hasResolved()) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Binding } from '../../src/Binding' | ||
|
||
describe('Binding: hasResolver()', function () { | ||
it('should return false if there is no resolver', function () { | ||
const binding = new Binding() | ||
|
||
this.assert.isFalse(binding.hasResolver()) | ||
}) | ||
|
||
it('should return true if there is a resolver', function () { | ||
const binding = new Binding(null, () => {}) | ||
|
||
this.assert.isTrue(binding.hasResolver()) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Binding } from '../../src/Binding' | ||
|
||
describe('Binding: isFactory()', function () { | ||
it('should return false if the binding is not a factory', function () { | ||
const binding = new Binding() | ||
|
||
this.assert.isFalse(binding.isFactory()) | ||
}) | ||
|
||
it('should return true if the binding is a factory', function () { | ||
const binding = new Binding(null, () => {}, true) | ||
|
||
this.assert.isTrue(binding.isFactory()) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Binding } from '../../src/Binding' | ||
|
||
describe('Binding: isInstance()', function () { | ||
it('should return false if the binding has a resolver', function () { | ||
const binding = new Binding(null, () => {}) | ||
|
||
this.assert.isFalse(binding.isInstance()) | ||
}) | ||
|
||
it('should return true if the binding has no resolver', function () { | ||
const binding = new Binding() | ||
|
||
this.assert.isTrue(binding.isInstance()) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Binding } from '../../src/Binding' | ||
|
||
describe('Binding: isSingleton()', function () { | ||
it('should return false if the binding has no resolver', function () { | ||
const binding = new Binding(null, null, false) | ||
|
||
this.assert.isFalse(binding.isSingleton()) | ||
}) | ||
|
||
it('should return false if the binding is a factory', function () { | ||
const binding = new Binding(null, () => {}, true) | ||
|
||
this.assert.isFalse(binding.isSingleton()) | ||
}) | ||
|
||
it('should return true if the binding has a resolved and is not a factory', function () { | ||
const binding = new Binding(null, () => {}, false) | ||
|
||
this.assert.isTrue(binding.isSingleton()) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Container } from '../../src/Container' | ||
import { Binding } from '../../src/Binding' | ||
|
||
describe('Binding: resolve()', function () { | ||
describe('for an instance', function () { | ||
it('should return the value', function () { | ||
const value = {} | ||
const binding = new Binding(value) | ||
|
||
const container = new Container() | ||
|
||
this.assert.equal(binding.resolve(container), value) | ||
}) | ||
}) | ||
|
||
describe('for a singleton', function () { | ||
it('should return the resolver\'s value', function () { | ||
const value = {} | ||
const resolver = () => value | ||
const binding = new Binding(null, resolver) | ||
|
||
const container = new Container() | ||
|
||
this.assert.equal(binding.resolve(container), value) | ||
}) | ||
|
||
it('should return the resolver\'s value for subsequent resolutions', function () { | ||
const value = {} | ||
const resolver = () => value | ||
const binding = new Binding(null, resolver) | ||
|
||
const container = new Container() | ||
|
||
binding.resolve(container) | ||
|
||
this.assert.equal(binding.resolve(container), value) | ||
}) | ||
}) | ||
|
||
describe('for a factory', function () { | ||
it('should return the resolver\'s value', function () { | ||
const resolver = () => Object.create({}) | ||
const binding = new Binding(null, resolver, true) | ||
|
||
const container = new Container() | ||
|
||
this.assert.deepEqual(binding.resolve(container), {}) | ||
}) | ||
|
||
it('should return a new value for subsequent resolutions', function () { | ||
const resolver = () => Object.create({}) | ||
const binding = new Binding(null, resolver, true) | ||
|
||
const container = new Container() | ||
|
||
const value = binding.resolve(container) | ||
|
||
this.assert.notEqual(binding.resolve(container), value) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Binding } from '../../src/Binding' | ||
|
||
describe('Binding: setHasResolved()', function () { | ||
it('should set the hasResolved property value', function () { | ||
const binding = new Binding() | ||
|
||
this.assert.isFalse(binding.hasResolved()) | ||
|
||
binding.setHasResolved(true) | ||
|
||
this.assert.isTrue(binding.hasResolved()) | ||
}) | ||
|
||
it('should return the binding', function () { | ||
const binding = new Binding() | ||
|
||
this.assert.equal(binding.setHasResolved(true), binding) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Binding } from '../../src/Binding' | ||
|
||
describe('Binding: setValue()', function () { | ||
it('should set the value property value', function () { | ||
const binding = new Binding() | ||
|
||
this.assert.isNull(binding.getValue()) | ||
|
||
binding.setValue(true) | ||
|
||
this.assert.isTrue(binding.getValue()) | ||
}) | ||
|
||
it('should return the binding', function () { | ||
const binding = new Binding() | ||
|
||
this.assert.equal(binding.setValue(true), binding) | ||
}) | ||
}) |