| OLD | NEW |
| 1 library angular.mock.test_injection; | 1 part of angular.mock; |
| 2 | 2 |
| 3 import 'package:angular/application_factory.dart'; | |
| 4 import 'package:angular/mock/module.dart'; | |
| 5 import 'package:di/di.dart'; | |
| 6 import 'package:di/dynamic_injector.dart'; | |
| 7 | |
| 8 _SpecInjector _currentSpecInjector = null; | 3 _SpecInjector _currentSpecInjector = null; |
| 9 | 4 |
| 10 class _SpecInjector { | 5 class _SpecInjector { |
| 11 DynamicInjector moduleInjector; | 6 DynamicInjector moduleInjector; |
| 12 DynamicInjector injector; | 7 DynamicInjector injector; |
| 13 dynamic injectiorCreateLocation; | 8 dynamic injectiorCreateLocation; |
| 14 final modules = <Module>[]; | 9 final modules = <Module>[]; |
| 15 final initFns = <Function>[]; | 10 final initFns = <Function>[]; |
| 16 | 11 |
| 17 _SpecInjector() { | 12 _SpecInjector() { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 injectiorCreateLocation = null; | 61 injectiorCreateLocation = null; |
| 67 } | 62 } |
| 68 } | 63 } |
| 69 | 64 |
| 70 /** | 65 /** |
| 71 * Allows the injection of instances into a test. See [module] on how to install
new | 66 * Allows the injection of instances into a test. See [module] on how to install
new |
| 72 * types into injector. | 67 * types into injector. |
| 73 * | 68 * |
| 74 * NOTE: Calling inject creates an injector, which prevents any more calls to [m
odule]. | 69 * NOTE: Calling inject creates an injector, which prevents any more calls to [m
odule]. |
| 75 * | 70 * |
| 76 * NOTE: [inject] will never return the result of [fn]. If you need to return a
[Future] | |
| 77 * for unittest to consume, take a look at [async], [clockTick], and [microLeap]
instead. | |
| 78 * | |
| 79 * Typical usage: | 71 * Typical usage: |
| 80 * | 72 * |
| 81 * test('wrap whole test', inject((TestBed tb) { | 73 * test('wrap whole test', inject((TestBed tb) { |
| 82 * tb.compile(...); | 74 * tb.compile(...); |
| 83 * })); | 75 * }); |
| 84 * | 76 * |
| 85 * test('wrap part of a test', () { | 77 * test('wrap part of a test', () { |
| 86 * module((Module module) { | 78 * module((Module module) { |
| 87 * module.type(Foo); | 79 * module.type(Foo); |
| 88 * }); | 80 * }); |
| 89 * inject((TestBed tb) { | 81 * inject((TestBed tb) { |
| 90 * tb.compile(...); | 82 * tb.compile(...); |
| 91 * }); | 83 * }); |
| 92 * }); | 84 * }); |
| 93 * | 85 * |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 : _currentSpecInjector.module(fnOrModule, stack); | 120 : _currentSpecInjector.module(fnOrModule, stack); |
| 129 } | 121 } |
| 130 } | 122 } |
| 131 | 123 |
| 132 /** | 124 /** |
| 133 * Call this method in your test harness [setUp] method to setup the injector. | 125 * Call this method in your test harness [setUp] method to setup the injector. |
| 134 */ | 126 */ |
| 135 void setUpInjector() { | 127 void setUpInjector() { |
| 136 _currentSpecInjector = new _SpecInjector(); | 128 _currentSpecInjector = new _SpecInjector(); |
| 137 _currentSpecInjector.module((Module m) { | 129 _currentSpecInjector.module((Module m) { |
| 138 m | 130 m..install(new AngularModule())..install(new AngularMockModule()); |
| 139 ..install(applicationFactory().ngModule) | |
| 140 ..install(new AngularMockModule()); | |
| 141 }); | 131 }); |
| 142 } | 132 } |
| 143 | 133 |
| 144 /** | 134 /** |
| 145 * Call this method in your test harness [tearDown] method to cleanup the inject
or. | 135 * Call this method in your test harness [tearDown] method to cleanup the inject
or. |
| 146 */ | 136 */ |
| 147 void tearDownInjector() { | 137 void tearDownInjector() { |
| 148 _currentSpecInjector = null; | 138 _currentSpecInjector = null; |
| 149 } | 139 } |
| OLD | NEW |