Browse Source

Add integration test for circular deps

develop
garrettmills 2 years ago
parent
commit
a76b586685
  1. 34
      test/integration/Circular.spec.js

34
test/integration/Circular.spec.js

@ -0,0 +1,34 @@
const { expect } = require('chai')
const Container = require('../../src/Container')
const Service = require('../../src/Service')
const DependencyInjector = require('../../src/DependencyInjector')
const Injectable = require('../../src/Injectable')
describe('[integration] circular dependencies', function() {
it('should resolve circular dependencies', function() {
class A extends Service {
static get services() {
return ['b']
}
}
class B extends Service {
static get services() {
return ['a']
}
}
const defs = { a: A, b: B }
const di = new DependencyInjector(new Container(defs))
const a = di.service('a')
const b = di.service('b')
expect(a).to.be.an.instanceof(A)
expect(b).to.be.an.instanceof(B)
expect(a.b).to.be.an.instanceof(B)
expect(b.a).to.be.an.instanceof(A)
expect(a.b.a).to.be.equal(a)
expect(b.a.b).to.be.equal(b)
})
})
Loading…
Cancel
Save