-
Notifications
You must be signed in to change notification settings - Fork 719
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix circular dependency error message (#1627)
* fix: updated planner to provide right circular dependent services * docs: update changelog * test: update test to avoid accessing class before initialization
- Loading branch information
1 parent
22cdcc0
commit d6f09a6
Showing
3 changed files
with
54 additions
and
1 deletion.
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,52 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { | ||
Container, | ||
inject, | ||
injectable, | ||
multiInject, | ||
} from '../../src/inversify'; | ||
|
||
describe('Issue 1515', () => { | ||
it('should not throw on false circular dependency', () => { | ||
@injectable() | ||
class Circle1 { | ||
constructor(@inject('circle-2') public readonly circle2: unknown) {} | ||
} | ||
|
||
@injectable() | ||
class Circle2 { | ||
constructor(@inject('circle-1') public circle1: unknown) {} | ||
} | ||
|
||
@injectable() | ||
class Multi1 {} | ||
@injectable() | ||
class Multi2 {} | ||
@injectable() | ||
class Multi3 {} | ||
|
||
@injectable() | ||
class Top { | ||
constructor( | ||
@multiInject('multi-inject') public readonly multis: unknown[], | ||
@inject('circle-1') public readonly circle1: unknown, | ||
) {} | ||
} | ||
|
||
const container: Container = new Container(); | ||
|
||
container.bind('multi-inject').to(Multi1); | ||
container.bind('multi-inject').to(Multi2); | ||
container.bind('multi-inject').to(Multi3); | ||
container.bind('circle-1').to(Circle1); | ||
container.bind('circle-2').to(Circle2); | ||
container.bind(Top).toSelf(); | ||
|
||
expect(() => { | ||
container.get(Top); | ||
}).to.throw( | ||
'Circular dependency found: Top --> circle-1 --> circle-2 --> circle-1', | ||
); | ||
}); | ||
}); |