diff --git a/test/_specs.dart b/test/_specs.dart index 8c9291c66..21d9dced9 100644 --- a/test/_specs.dart +++ b/test/_specs.dart @@ -157,11 +157,15 @@ class Logger implements List { List _asyncQueue = []; -nextTurn() { +nextTurn([bool runUntilEmpty = false]) { // copy the queue as it may change. var toRun = new List.from(_asyncQueue); _asyncQueue = []; toRun.forEach((fn) => fn()); + + if (runUntilEmpty && !_asyncQueue.isEmpty) { + nextTurn(runUntilEmpty); + } } async(Function fn) => diff --git a/test/_specs_spec.dart b/test/_specs_spec.dart index 0a5740194..22190e46c 100644 --- a/test/_specs_spec.dart +++ b/test/_specs_spec.dart @@ -88,6 +88,22 @@ main() { })(); }); + it('should run all the async calls if asked', () { + var log = []; + async(() { + new Future.value('s') + .then((_) { + log.add('firstThen'); + new Future.value('t').then((_) { + log.add('2ndThen'); + }); + }); + expect(log.join(' ')).toEqual(''); + nextTurn(true); + expect(log.join(' ')).toEqual('firstThen 2ndThen'); + })(); + }); + it('should complain if you dangle callbacks', () { expect(() { diff --git a/test/compiler_spec.dart b/test/compiler_spec.dart index 4aff600c1..03de0c50a 100644 --- a/test/compiler_spec.dart +++ b/test/compiler_spec.dart @@ -397,7 +397,7 @@ main() { module.directive(PublishMeComponent); })); - it('should create a simple component', inject(() { + it('should create a simple component', async(inject(() { $rootScope.name = 'OUTTER'; $rootScope.sep = '-'; var element = $(r'
{{name}}{{sep}}{{$id}}:{{name}}{{sep}}{{$id}}
'); @@ -405,39 +405,37 @@ main() { Block block = blockType(injector, element); $rootScope.$digest(); - SimpleComponent.lastTemplateLoader.template.then(expectAsync1((_) { - expect(element.textWithShadow()).toEqual('OUTTER-_1:INNER_2(OUTTER-_1)'); - })); - })); + nextTurn(); + expect(element.textWithShadow()).toEqual('OUTTER-_1:INNER_2(OUTTER-_1)'); + }))); - it('should create a component that can access parent scope', inject(() { + it('should create a component that can access parent scope', async(inject(() { $rootScope.fromParent = "should not be used"; $rootScope.val = "poof"; var element = $(''); $compile(element)(injector, element); - ParentExpressionComponent.lastTemplateLoader.template.then(expectAsync1((_) { - expect(renderedText(element)).toEqual('inside poof'); - })); - })); + nextTurn(); + expect(renderedText(element)).toEqual('inside poof'); + }))); - it('should behave nicely if a mapped attribute is missing', inject(() { + it('should behave nicely if a mapped attribute is missing', async(inject(() { var element = $(''); $compile(element)(injector, element); - ParentExpressionComponent.lastTemplateLoader.template.then(expectAsync1((_) { - expect(renderedText(element)).toEqual('inside '); - })); - })); - it('should behave nicely if a mapped attribute evals to null', inject(() { + nextTurn(); + expect(renderedText(element)).toEqual('inside '); + }))); + + it('should behave nicely if a mapped attribute evals to null', async(inject(() { $rootScope.val = null; var element = $(''); $compile(element)(injector, element); - ParentExpressionComponent.lastTemplateLoader.template.then(expectAsync1((_) { - expect(renderedText(element)).toEqual('inside '); - })); - })); + + nextTurn(); + expect(renderedText(element)).toEqual('inside '); + }))); it('should create a component with IO', inject(() { var element = $(r'
'); @@ -471,14 +469,14 @@ main() { }, throwsA(contains('No provider found for LocalAttrDirective! (resolving LocalAttrDirective)'))); })); - it('should publish component controller into the scope', inject(() { + it('should publish component controller into the scope', async(inject(() { var element = $(r'
'); $compile(element)(injector, element); $rootScope.$apply(); - PublishMeComponent.lastTemplateLoader.template.then(expectAsync1((_) { - expect(element.textWithShadow()).toEqual('WORKED'); - })); - })); + + nextTurn(); + expect(element.textWithShadow()).toEqual('WORKED'); + }))); }); describe('controller scoping', () { @@ -502,10 +500,8 @@ main() { class SimpleComponent { static String $template = r'{{name}}{{sep}}{{$id}}(SHADOW-CONTENT)'; - static TemplateLoader lastTemplateLoader; SimpleComponent(Scope scope, TemplateLoader templateLoader) { scope.name = 'INNER'; - lastTemplateLoader = templateLoader; } } @@ -529,19 +525,11 @@ class CamelCaseMapComponent { class ParentExpressionComponent { static String $template = '
inside {{fromParent()}}
'; static Map $map = {"fromParent": "&"}; - static TemplateLoader lastTemplateLoader; - ParentExpressionComponent(Scope shadowScope, TemplateLoader templateLoader) { - lastTemplateLoader = templateLoader; - } } class PublishMeComponent { static String $template = r'{{ctrlName.value}}'; static String $publishAs = 'ctrlName'; - static TemplateLoader lastTemplateLoader; String value = 'WORKED'; - PublishMeComponent(TemplateLoader templateLoader) { - lastTemplateLoader = templateLoader; - } } diff --git a/test/shadow_root_options_spec.dart b/test/shadow_root_options_spec.dart index 246aa68ff..afe881b50 100644 --- a/test/shadow_root_options_spec.dart +++ b/test/shadow_root_options_spec.dart @@ -45,35 +45,31 @@ main() { })); describe('shadow dom options', () { - it('should respect the apply-author-style option', inject(() { + it('should respect the apply-author-style option', async(inject(() { var element = $( '' + 'not included' + 'not included'); element.forEach((elt) { document.body.append(elt); }); // we need the computed style. $compile(element)(injector, element); - ApplyAuthorStyleComponent.lastTemplateLoader.then(expectAsync1((_) { - expect(element[1].shadowRoot.query('div').getComputedStyle().border).toContain('3px solid'); - })); - DefaultOptionsComponent.lastTemplateLoader.then(expectAsync1((_) { - // ""0px none"" is the default style. - expect(element[2].shadowRoot.query('div').getComputedStyle().border).toContain('0px none'); - })); - })); - it('should respect the reset-style-inheritance option', inject(() { + nextTurn(); + expect(element[1].shadowRoot.query('div').getComputedStyle().border).toContain('3px solid'); + // ""0px none"" is the default style. + expect(element[2].shadowRoot.query('div').getComputedStyle().border).toContain('0px none'); + }))); + + it('should respect the reset-style-inheritance option', async(inject(() { var element = $( '' + // font-size inherit's by default 'not included' + 'not included'); element.forEach((elt) { document.body.append(elt); }); // we need the computed style. $compile(element)(injector, element); - ResetStyleInheritanceComponent.lastTemplateLoader.then(expectAsync1((_) { - expect(element[1].shadowRoot.query('div').getComputedStyle().fontSize).toEqual('16px'); - })); - DefaultOptionsComponent.lastTemplateLoader.then(expectAsync1((_) { - expect(element[2].shadowRoot.query('div').getComputedStyle().fontSize).toEqual('20px'); - })); - })); + + nextTurn(); + expect(element[1].shadowRoot.query('div').getComputedStyle().fontSize).toEqual('16px'); + expect(element[2].shadowRoot.query('div').getComputedStyle().fontSize).toEqual('20px'); + }))); }); } diff --git a/test/templateurl_spec.dart b/test/templateurl_spec.dart index 2dd748e1f..7a1db784a 100644 --- a/test/templateurl_spec.dart +++ b/test/templateurl_spec.dart @@ -22,10 +22,6 @@ class HtmlAndCssComponent { class InlineWithCssComponent { static String $template = '
inline!
'; static String $cssUrl = 'simple.css'; - static TemplateLoader lastTemplateLoader; - InlineWithCssComponent(TemplateLoader templateLoader) { - lastTemplateLoader = templateLoader; - } } class OnlyCssComponent { @@ -79,55 +75,58 @@ main() { $http.assertAllGetsCalled(); })); - it('should replace element with template from url', inject((MockHttp $http, Compiler $compile, Scope $rootScope, Log log, Injector injector) { + it('should replace element with template from url', async(inject((MockHttp $http, Compiler $compile, Scope $rootScope, Log log, Injector injector) { $http.expectGET('simple.html', '
Simple!
'); var element = $('
ignore
'); $compile(element)(injector, element); - $http.flush().then(expectAsync1((data) { - expect(renderedText(element)).toEqual('Simple!'); - // Note: There is no ordering. It is who ever comes off the wire first! - expect(log.result()).toEqual('LOG; SIMPLE'); - })); - })); + $http.flush(); + nextTurn(true); - it('should load template from URL once', inject((MockHttp $http, Compiler $compile, Scope $rootScope, Log log, Injector injector) { + expect(renderedText(element)).toEqual('Simple!'); + // Note: There is no ordering. It is who ever comes off the wire first! + expect(log.result()).toEqual('LOG; SIMPLE'); + }))); + + it('should load template from URL once', async(inject((MockHttp $http, Compiler $compile, Scope $rootScope, Log log, Injector injector) { $http.expectGET('simple.html', '
Simple!
', times: 2); var element = $('
ignoreignore
'); $compile(element)(injector, element); - $http.flush().then(expectAsync1((data) { - expect(renderedText(element)).toEqual('Simple!Simple!'); - // Note: There is no ordering. It is who ever comes off the wire first! - expect(log.result()).toEqual('LOG; LOG; SIMPLE; SIMPLE'); - })); - })); + $http.flush(); + nextTurn(true); - it('should load a CSS file into a style', inject((MockHttp $http, Compiler $compile, Scope $rootScope, Log log, Injector injector) { + expect(renderedText(element)).toEqual('Simple!Simple!'); + // Note: There is no ordering. It is who ever comes off the wire first! + expect(log.result()).toEqual('LOG; LOG; SIMPLE; SIMPLE'); + }))); + + it('should load a CSS file into a style', async(inject((MockHttp $http, Compiler $compile, Scope $rootScope, Log log, Injector injector) { $http.expectGET('simple.html', '
Simple!
'); var element = $('
ignore
'); $compile(element)(injector, element); - $http.flush().then(expectAsync1((data) { - expect(renderedText(element)).toEqual('@import "simple.css"Simple!'); - expect(element[0].nodes[0].shadowRoot.innerHtml).toEqual( - '
Simple!
' - ); - // Note: There is no ordering. It is who ever comes off the wire first! - expect(log.result()).toEqual('LOG; SIMPLE'); - })); - })); + $http.flush(); + nextTurn(true); - it('should load a CSS file with a \$template', inject((Compiler $compile, Scope $rootScope, Injector injector) { + expect(renderedText(element)).toEqual('@import "simple.css"Simple!'); + expect(element[0].nodes[0].shadowRoot.innerHtml).toEqual( + '
Simple!
' + ); + // Note: There is no ordering. It is who ever comes off the wire first! + expect(log.result()).toEqual('LOG; SIMPLE'); + }))); + + it('should load a CSS file with a \$template', async(inject((Compiler $compile, Scope $rootScope, Injector injector) { var element = $('
ignore
'); $compile(element)(injector, element); - InlineWithCssComponent.lastTemplateLoader.template.then(expectAsync1((_) { - expect(renderedText(element)).toEqual('@import "simple.css"inline!'); - })); - })); + + nextTurn(true); + expect(renderedText(element)).toEqual('@import "simple.css"inline!'); + }))); it('should load a CSS with no template', inject((Compiler $compile, Scope $rootScope, Injector injector) { var element = $('
ignore
'); @@ -136,7 +135,7 @@ main() { expect(renderedText(element)).toEqual('@import "simple.css"'); })); - it('should load the CSS before the template is loaded', inject((MockHttp $http, Compiler $compile, Scope $rootScope, Injector injector) { + it('should load the CSS before the template is loaded', async(inject((MockHttp $http, Compiler $compile, Scope $rootScope, Injector injector) { $http.expectGET('simple.html', '
Simple!
'); var element = $('ignore'); @@ -145,10 +144,8 @@ main() { // The HTML is not loaded yet, but the CSS @import should be in the DOM. expect(renderedText(element)).toEqual('@import "simple.css"'); - $http.flush().then(expectAsync1((data) { - expect(renderedText(element)).toEqual('@import "simple.css"Simple!'); - })); - })); + nextTurn(true); + expect(renderedText(element)).toEqual('@import "simple.css"Simple!'); + }))); }); } -