From 30253592ff0b8ad1ce67ba771f5c2c68c376b26a Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 13 Mar 2015 15:30:10 +0100 Subject: [PATCH] refactor(tests): refactor some tests to use the test injector --- .../test/core/compiler/style_inliner_spec.js | 48 +++++++++++-------- .../angular2/test/directives/foreach_spec.js | 39 ++++++--------- 2 files changed, 41 insertions(+), 46 deletions(-) diff --git a/modules/angular2/test/core/compiler/style_inliner_spec.js b/modules/angular2/test/core/compiler/style_inliner_spec.js index 3129d30af7..bec4c549a0 100644 --- a/modules/angular2/test/core/compiler/style_inliner_spec.js +++ b/modules/angular2/test/core/compiler/style_inliner_spec.js @@ -1,6 +1,7 @@ import { AsyncTestCompleter, beforeEach, + beforeEachBindings, ddescribe, describe, el, @@ -17,29 +18,26 @@ import {Promise, PromiseWrapper} from 'angular2/src/facade/async'; import {Map, MapWrapper} from 'angular2/src/facade/collection'; import {XHR} from 'angular2/src/core/compiler/xhr/xhr'; -import {UrlResolver} from 'angular2/src/core/compiler/url_resolver'; -import {StyleUrlResolver} from 'angular2/src/core/compiler/style_url_resolver'; + +import {bind} from 'angular2/di'; export function main() { describe('StyleInliner', () => { - var xhr, inliner; - - beforeEach(() => { - xhr = new FakeXHR(); - var urlResolver = new UrlResolver(); - var styleUrlResolver = new StyleUrlResolver(urlResolver); - inliner = new StyleInliner(xhr, styleUrlResolver, urlResolver); - }); + beforeEachBindings(() => [ + bind(XHR).toClass(FakeXHR), + ]); describe('loading', () => { - it('should return a string when there is no import statement', () => { + + it('should return a string when there is no import statement', inject([StyleInliner], (inliner) => { var css = '.main {}'; var loadedCss = inliner.inlineImports(css, 'http://base'); expect(loadedCss).not.toBePromise(); expect(loadedCss).toEqual(css); - }); + })); - it('should inline @import rules', inject([AsyncTestCompleter], (async) => { + it('should inline @import rules', + inject([XHR, StyleInliner, AsyncTestCompleter], (xhr, inliner, async) => { xhr.reply('http://base/one.css', '.one {}'); var css = '@import url("one.css");.main {}'; var loadedCss = inliner.inlineImports(css, 'http://base'); @@ -56,7 +54,8 @@ export function main() { ); })); - it('should support url([unquoted url]) in @import rules', inject([AsyncTestCompleter], (async) => { + it('should support url([unquoted url]) in @import rules', + inject([XHR, StyleInliner, AsyncTestCompleter], (xhr, inliner, async) => { xhr.reply('http://base/one.css', '.one {}'); var css = '@import url(one.css);.main {}'; var loadedCss = inliner.inlineImports(css, 'http://base'); @@ -73,7 +72,8 @@ export function main() { ); })); - it('should handle @import error gracefuly', inject([AsyncTestCompleter], (async) => { + it('should handle @import error gracefuly', + inject([StyleInliner, AsyncTestCompleter], (inliner, async) => { var css = '@import "one.css";.main {}'; var loadedCss = inliner.inlineImports(css, 'http://base'); expect(loadedCss).toBePromise(); @@ -89,7 +89,8 @@ export function main() { ); })); - it('should inline multiple @import rules', inject([AsyncTestCompleter], (async) => { + it('should inline multiple @import rules', + inject([XHR, StyleInliner, AsyncTestCompleter], (xhr, inliner, async) => { xhr.reply('http://base/one.css', '.one {}'); xhr.reply('http://base/two.css', '.two {}'); var css = '@import "one.css";@import "two.css";.main {}'; @@ -107,7 +108,8 @@ export function main() { ); })); - it('should inline nested @import rules', inject([AsyncTestCompleter], (async) => { + it('should inline nested @import rules', + inject([XHR, StyleInliner, AsyncTestCompleter], (xhr, inliner, async) => { xhr.reply('http://base/one.css', '@import "two.css";.one {}'); xhr.reply('http://base/two.css', '.two {}'); var css = '@import "one.css";.main {}'; @@ -125,7 +127,8 @@ export function main() { ); })); - it('should handle circular dependencies gracefuly', inject([AsyncTestCompleter], (async) => { + it('should handle circular dependencies gracefuly', + inject([XHR, StyleInliner, AsyncTestCompleter], (xhr, inliner, async) => { xhr.reply('http://base/one.css', '@import "two.css";.one {}'); xhr.reply('http://base/two.css', '@import "one.css";.two {}'); var css = '@import "one.css";.main {}'; @@ -143,7 +146,8 @@ export function main() { ); })); - it('should handle invalid @import fracefuly', inject([AsyncTestCompleter], (async) => { + it('should handle invalid @import fracefuly', + inject([StyleInliner, AsyncTestCompleter], (inliner, async) => { // Invalid rule: the url is not quoted var css = '@import one.css;.main {}'; var loadedCss = inliner.inlineImports(css, 'http://base/'); @@ -162,7 +166,8 @@ export function main() { }); describe('media query', () => { - it('should wrap inlined content in media query', inject([AsyncTestCompleter], (async) => { + it('should wrap inlined content in media query', + inject([XHR, StyleInliner, AsyncTestCompleter], (xhr, inliner, async) => { xhr.reply('http://base/one.css', '.one {}'); var css = '@import "one.css" (min-width: 700px) and (orientation: landscape);'; var loadedCss = inliner.inlineImports(css, 'http://base/'); @@ -181,7 +186,8 @@ export function main() { }); describe('url rewritting', () => { - it('should rewrite url in inlined content', inject([AsyncTestCompleter], (async) => { + it('should rewrite url in inlined content', + inject([XHR, StyleInliner, AsyncTestCompleter], (xhr, inliner, async) => { // it should rewrite both '@import' and 'url()' xhr.reply('http://base/one.css', '@import "./nested/two.css";.one {background-image: url("one.jpg");}'); xhr.reply('http://base/nested/two.css', '.two {background-image: url("../img/two.jpg");}'); diff --git a/modules/angular2/test/directives/foreach_spec.js b/modules/angular2/test/directives/foreach_spec.js index 1d21c021ea..da8a47adce 100644 --- a/modules/angular2/test/directives/foreach_spec.js +++ b/modules/angular2/test/directives/foreach_spec.js @@ -1,6 +1,7 @@ import { AsyncTestCompleter, beforeEach, + beforeEachBindings, ddescribe, describe, el, @@ -15,16 +16,9 @@ import {DOM} from 'angular2/src/dom/dom_adapter'; import {ListWrapper} from 'angular2/src/facade/collection'; import {Injector} from 'angular2/di'; -import {Lexer, Parser, ChangeDetector, dynamicChangeDetection} from 'angular2/change_detection'; -import {Compiler, CompilerCache} from 'angular2/src/core/compiler/compiler'; -import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader'; -import {NativeShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy'; -import {TemplateLoader} from 'angular2/src/core/compiler/template_loader'; -import {ComponentUrlMapper} from 'angular2/src/core/compiler/component_url_mapper'; -import {UrlResolver} from 'angular2/src/core/compiler/url_resolver'; -import {StyleUrlResolver} from 'angular2/src/core/compiler/style_url_resolver'; -import {CssProcessor} from 'angular2/src/core/compiler/css_processor'; +import {Compiler} from 'angular2/src/core/compiler/compiler'; +import {TemplateResolver} from 'angular2/src/core/compiler/template_resolver'; import {Template} from 'angular2/src/core/annotations/template'; import {Decorator, Component, Viewport} from 'angular2/src/core/annotations/annotations'; @@ -33,25 +27,20 @@ import {MockTemplateResolver} from 'angular2/src/mock/template_resolver_mock'; import {Foreach} from 'angular2/src/directives/foreach'; +import {bind} from 'angular2/di'; + export function main() { describe('foreach', () => { var view, cd, compiler, component, tplResolver; - beforeEach(() => { - var urlResolver = new UrlResolver(); - tplResolver = new MockTemplateResolver(); - compiler = new Compiler( - dynamicChangeDetection, - new TemplateLoader(null, null), - new DirectiveMetadataReader(), - new Parser(new Lexer()), - new CompilerCache(), - new NativeShadowDomStrategy(new StyleUrlResolver(urlResolver)), - tplResolver, - new ComponentUrlMapper(), - urlResolver, - new CssProcessor(null) - ); - }); + + beforeEachBindings(() => [ + bind(TemplateResolver).toClass(MockTemplateResolver), + ]); + + beforeEach(inject([Compiler, TemplateResolver], (c, t) => { + compiler = c; + tplResolver = t; + })); function createView(pv) { component = new TestComponent();