| OLD | NEW |
| 1 library angular.mock.test_bed_spec; | 1 library angular.mock.test_bed_spec; |
| 2 | 2 |
| 3 import '../_specs.dart'; | 3 import '../_specs.dart'; |
| 4 | 4 |
| 5 void main() { | 5 main() => |
| 6 describe('test bed', () { | 6 describe('test bed', () { |
| 7 TestBed _; | 7 TestBed _; |
| 8 Compiler compile; | 8 Compiler $compile; |
| 9 Injector injector; | 9 Injector injector; |
| 10 Scope rootScope; | 10 Scope $rootScope; |
| 11 | 11 |
| 12 beforeEachModule((Module module) { | 12 beforeEach(module((Module module) { |
| 13 module..type(MyTestBedDirective); | 13 module..type(MyTestBedDirective); |
| 14 return (TestBed tb) => _ = tb; | 14 return (TestBed tb) => _ = tb; |
| 15 })); |
| 16 |
| 17 it('should allow for a scope-based compile', () { |
| 18 |
| 19 inject((Scope scope) { |
| 20 Scope childScope = scope.createChild({}); |
| 21 |
| 22 var element = $('<div my-directive probe="i"></div>'); |
| 23 _.compile(element, scope: childScope); |
| 24 |
| 25 Probe probe = _.rootScope.context['i']; |
| 26 var directiveInst = probe.directive(MyTestBedDirective); |
| 27 |
| 28 childScope.destroy(); |
| 29 |
| 30 expect(directiveInst.destroyed).toBe(true); |
| 15 }); | 31 }); |
| 32 }); |
| 16 | 33 |
| 17 it('should allow for a scope-based compile', () { | 34 }); |
| 18 | 35 |
| 19 inject((Scope scope) { | 36 @NgDirective(selector: '[my-directive]') |
| 20 Scope childScope = scope.createChild({}); | |
| 21 | |
| 22 _.compile('<div my-directive probe="i"></div>', scope: childScope); | |
| 23 | |
| 24 Probe probe = _.rootScope.context['i']; | |
| 25 var directiveInst = probe.directive(MyTestBedDirective); | |
| 26 | |
| 27 childScope.destroy(); | |
| 28 | |
| 29 expect(directiveInst.destroyed).toBe(true); | |
| 30 }); | |
| 31 }); | |
| 32 | |
| 33 }); | |
| 34 } | |
| 35 | |
| 36 @Decorator(selector: '[my-directive]') | |
| 37 class MyTestBedDirective { | 37 class MyTestBedDirective { |
| 38 bool destroyed = false; | 38 bool destroyed = false; |
| 39 | 39 |
| 40 MyTestBedDirective(Scope scope) { | 40 MyTestBedDirective(Scope scope) { |
| 41 scope.on(ScopeEvent.DESTROY).listen((_) { | 41 scope.on(ScopeEvent.DESTROY).listen((_) { |
| 42 destroyed = true; | 42 destroyed = true; |
| 43 }); | 43 }); |
| 44 } | 44 } |
| 45 } | 45 } |
| OLD | NEW |