Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit c83d11c

Browse files
committed
refactor(tests): change tests to use flushGET instead of expectGET
Closes #1433
1 parent 635f9d0 commit c83d11c

File tree

5 files changed

+74
-138
lines changed

5 files changed

+74
-138
lines changed

test/core/templateurl_spec.dart

+27-47
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,15 @@ _run({resolveUrls, staticMode}) {
9898
Injector injector, VmTurnZone zone, MockHttpBackend backend,
9999
DirectiveMap directives) {
100100

101-
backend
102-
..whenGET('PREFIX:${prefix}simple.html').respond('<div log="SIMPLE">Simple!</div>')
103-
..whenGET('PREFIX:${prefix}simple.css').respond('.hello{}');
104-
105101
var element = e('<div><html-and-css log>ignore</html-and-css><div>');
106102
zone.run(() {
107103
compile([element], directives)(rootScope, null, [element]);
108104
});
109105

110-
backend.flush();
106+
backend
107+
..flushGET('PREFIX:${prefix}simple.css').respond('.hello{}')
108+
..flushGET('PREFIX:${prefix}simple.html').respond('<div log="SIMPLE">Simple!</div>');
109+
111110
microLeap();
112111

113112
expect(element).toHaveText('.hello{}Simple!');
@@ -131,13 +130,10 @@ _run({resolveUrls, staticMode}) {
131130
it('should replace element with template from url', async(
132131
(Http http, Compiler compile, Scope rootScope, Logger log,
133132
Injector injector, MockHttpBackend backend, DirectiveMap directives) {
134-
backend.expectGET('${prefix}simple.html').respond(200, '<div log="SIMPLE">Simple!<img src="a.png"></div>');
135-
136133
var element = es('<div><simple-url log>ignore</simple-url><div>');
137134
compile(element, directives)(rootScope, null, element);
138135

139-
microLeap();
140-
backend.flush();
136+
backend.flushGET('${prefix}simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
141137
microLeap();
142138

143139
expect(element[0]).toHaveText('Simple!');
@@ -149,17 +145,14 @@ _run({resolveUrls, staticMode}) {
149145
it('should load template from URL once', async(
150146
(Http http, Compiler compile, Scope rootScope, Logger log,
151147
Injector injector, MockHttpBackend backend, DirectiveMap directives) {
152-
backend.whenGET('${prefix}simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
153-
154148
var element = es(
155149
'<div>'
156150
'<simple-url log>ignore</simple-url>'
157151
'<simple-url log>ignore</simple-url>'
158152
'<div>');
159153
compile(element, directives)(rootScope, null, element);
160154

161-
microLeap();
162-
backend.flush();
155+
backend.flushGET('${prefix}simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
163156
microLeap();
164157

165158
expect(element.first).toHaveText('Simple!Simple!');
@@ -172,15 +165,13 @@ _run({resolveUrls, staticMode}) {
172165
it('should load a CSS file into a style', async(
173166
(Http http, Compiler compile, Scope rootScope, Logger log,
174167
Injector injector, MockHttpBackend backend, DirectiveMap directives) {
175-
backend
176-
..expectGET('${prefix}simple.css').respond(200, '.hello{}')
177-
..expectGET('${prefix}simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
178-
179168
var element = e('<div><html-and-css log>ignore</html-and-css><div>');
180169
compile([element], directives)(rootScope, null, [element]);
181170

182-
microLeap();
183-
backend.flush();
171+
backend
172+
..flushGET('${prefix}simple.css').respond(200, '.hello{}')
173+
..flushGET('${prefix}simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
174+
184175
microLeap();
185176

186177
expect(element).toHaveText('.hello{}Simple!');
@@ -196,25 +187,23 @@ _run({resolveUrls, staticMode}) {
196187
(Http http, Compiler compile, Scope rootScope, Injector injector,
197188
MockHttpBackend backend, DirectiveMap directives) {
198189
var element = es('<div><inline-with-css log>ignore</inline-with-css><div>');
199-
backend.expectGET('${prefix}simple.css').respond(200, '.hello{}');
200190
compile(element, directives)(rootScope, null, element);
201191

192+
backend.flushGET('${prefix}simple.css').respond(200, '.hello{}');
202193
microLeap();
203-
backend.flush();
204-
microLeap();
194+
205195
expect(element[0]).toHaveText('.hello{}inline!');
206196
}));
207197

208198
it('should ignore CSS load errors ', async(
209199
(Http http, Compiler compile, Scope rootScope, Injector injector,
210200
MockHttpBackend backend, DirectiveMap directives) {
211201
var element = es('<div><inline-with-css log>ignore</inline-with-css><div>');
212-
backend.expectGET('${prefix}simple.css').respond(500, 'some error');
213202
compile(element, directives)(rootScope, null, element);
214203

204+
backend.flushGET('${prefix}simple.css').respond(500, 'some error');
215205
microLeap();
216-
backend.flush();
217-
microLeap();
206+
218207
expect(element.first).toHaveText(
219208
'/*\n'
220209
'HTTP 500: some error\n'
@@ -226,28 +215,25 @@ _run({resolveUrls, staticMode}) {
226215
(Http http, Compiler compile, Scope rootScope, Injector injector,
227216
MockHttpBackend backend, DirectiveMap directives) {
228217
var element = es('<div><only-css log>ignore</only-css><div>');
229-
backend.expectGET('${prefix}simple.css').respond(200, '.hello{}');
230218
compile(element, directives)(rootScope, null, element);
231219

220+
backend.flushGET('${prefix}simple.css').respond(200, '.hello{}');
232221
microLeap();
233-
backend.flush();
234-
microLeap();
222+
235223
expect(element[0]).toHaveText('.hello{}');
236224
}));
237225

238226
it('should load the CSS before the template is loaded', async(
239227
(Http http, Compiler compile, Scope rootScope, Injector injector,
240228
MockHttpBackend backend, DirectiveMap directives) {
241-
backend
242-
..expectGET('${prefix}simple.css').respond(200, '.hello{}')
243-
..expectGET('${prefix}simple.html').respond(200, '<div>Simple!</div>');
244-
245229
var element = es('<html-and-css>ignore</html-and-css>');
246230
compile(element, directives)(rootScope, null, element);
247231

232+
backend
233+
..flushGET('${prefix}simple.css').respond(200, '.hello{}')
234+
..flushGET('${prefix}simple.html').respond(200, '<div>Simple!</div>');
248235
microLeap();
249-
backend.flush();
250-
microLeap();
236+
251237
expect(element.first).toHaveText('.hello{}Simple!');
252238
}));
253239
});
@@ -262,16 +248,13 @@ _run({resolveUrls, staticMode}) {
262248
it('should load multiple CSS files into a style', async(
263249
(Http http, Compiler compile, Scope rootScope, Logger log,
264250
Injector injector, MockHttpBackend backend, DirectiveMap directives) {
265-
backend
266-
..expectGET('${prefix}simple.css').respond(200, '.hello{}')
267-
..expectGET('${prefix}another.css').respond(200, '.world{}')
268-
..expectGET('${prefix}simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
269-
270251
var element = e('<div><html-and-css log>ignore</html-and-css><div>');
271252
compile([element], directives)(rootScope, null, [element]);
272253

273-
microLeap();
274-
backend.flush();
254+
backend
255+
..flushGET('${prefix}simple.css').respond(200, '.hello{}')
256+
..flushGET('${prefix}another.css').respond(200, '.world{}')
257+
..flushGET('${prefix}simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
275258
microLeap();
276259

277260
expect(element).toHaveText('.hello{}.world{}Simple!');
@@ -295,15 +278,12 @@ _run({resolveUrls, staticMode}) {
295278
it('should load css from the style cache for the second component', async(
296279
(Http http, Compiler compile, MockHttpBackend backend, RootScope rootScope,
297280
DirectiveMap directives, Injector injector) {
298-
backend
299-
..expectGET('${prefix}simple.css').respond(200, '.hello{}')
300-
..expectGET('${prefix}simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
301-
302281
var element = e('<div><html-and-css>ignore</html-and-css><div>');
303282
compile([element], directives)(rootScope, null, [element]);
304283

305-
microLeap();
306-
backend.flush();
284+
backend
285+
..flushGET('${prefix}simple.css').respond(200, '.hello{}')
286+
..flushGET('${prefix}simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
307287
microLeap();
308288

309289
expect(element.children[0].shadowRoot).toHaveHtml(

test/core_dom/view_cache_spec.dart

+1-5
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,10 @@ main() {
2020

2121
expect(cache.fromHtml(HTML, directives)).toBe(firstFactory);
2222

23-
// Also for fromUrl
24-
backend.whenGET('template.url').respond(200, HTML);
25-
2623
var httpFactory;
2724
cache.fromUrl('template.url', directives, Uri.base).then((f) => httpFactory = f);
2825

29-
microLeap();
30-
backend.flush();
26+
backend.flushGET('template.url').respond(200, HTML);
3127
microLeap();
3228

3329
expect(httpFactory).toBe(firstFactory);

test/core_dom/web_platform_spec.dart

+26-47
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,14 @@ main() {
1919
it('should scope styles to shadow dom across browsers.',
2020
async((TestBed _, MockHttpBackend backend, WebPlatform platform) {
2121

22-
backend
23-
..expectGET('${TEST_SERVER_BASE_PREFIX}test/core_dom/style.css').respond(200, 'span { background-color: red; '
24-
'}')
25-
..expectGET('${TEST_SERVER_BASE_PREFIX}test/core_dom/template.html').respond(200, '<span>foo</span>');
26-
2722
Element element = e('<span><test-wptc><span>ignore'
2823
'</span></test-wptc></span>');
2924

3025
_.compile(element);
3126

32-
microLeap();
33-
backend.flush();
34-
microLeap();
27+
backend
28+
..flushGET('${TEST_SERVER_BASE_PREFIX}test/core_dom/style.css').respond(200, 'span {background-color: red;}')
29+
..flushGET('${TEST_SERVER_BASE_PREFIX}test/core_dom/template.html').respond(200, '<span>foo</span>');
3530

3631
try {
3732
document.body.append(element);
@@ -58,37 +53,27 @@ main() {
5853
it('should not crash with an attribute selector; but wont work either..',
5954
async((TestBed _, MockHttpBackend backend, WebPlatform platform) {
6055

61-
backend
62-
..expectGET('${TEST_SERVER_BASE_PREFIX}test/core_dom/style.css').respond(200, 'span { background-color: red; '
63-
'}')
64-
..expectGET('${TEST_SERVER_BASE_PREFIX}test/core_dom/template.html').respond(200, '<span>foo</span>');
65-
6656
Element element = e('<span><test-wptca a><span>ignore'
6757
'</span></test-wptca></span>');
6858

6959
_.compile(element);
7060

71-
microLeap();
72-
backend.flush();
73-
microLeap();
61+
backend
62+
..flushGET('${TEST_SERVER_BASE_PREFIX}test/core_dom/style.css').respond(200, 'span{background-color: red}')
63+
..flushGET('${TEST_SERVER_BASE_PREFIX}test/core_dom/template.html').respond(200, '<span>foo</span>');
7464
}));
7565

7666
it('should scope :host styles to the primary element.',
7767
async((TestBed _, MockHttpBackend backend, WebPlatform platform) {
7868

79-
backend
80-
..expectGET('${TEST_SERVER_BASE_PREFIX}test/core_dom/style.css').respond(200, ':host {'
81-
'background-color: red; }')
82-
..expectGET('${TEST_SERVER_BASE_PREFIX}test/core_dom/template.html').respond(200, '<span>foo</span>');
83-
8469
Element element = e('<span><test-wptc><span>ignore'
8570
'</span></test-wptc></span>');
8671

8772
_.compile(element);
8873

89-
microLeap();
90-
backend.flush();
91-
microLeap();
74+
backend
75+
..flushGET('${TEST_SERVER_BASE_PREFIX}test/core_dom/style.css').respond(200, ':host {background-color: red; }')
76+
..flushGET('${TEST_SERVER_BASE_PREFIX}test/core_dom/template.html').respond(200, '<span>foo</span>');
9277

9378
try {
9479
document.body.append(element);
@@ -109,21 +94,17 @@ main() {
10994
xit('should scope ::content rules to component content.',
11095
async((TestBed _, MockHttpBackend backend, WebPlatform platform) {
11196

112-
backend
113-
..expectGET('style.css').respond(200,
114-
"polyfill-next-selector { content: ':host span:not([:host])'; }"
115-
"::content span { background-color: red; }")
116-
..expectGET('template.html').respond(200,
117-
'<span><content></content></span>');
118-
11997
Element element = e('<test-wptc><span>RED'
12098
'</span></test-wptc>');
12199

122100
_.compile(element);
123101

124-
microLeap();
125-
backend.flush();
126-
microLeap();
102+
backend
103+
..flushGET('style.css').respond(200,
104+
"polyfill-next-selector { content: ':host span:not([:host])'; }"
105+
"::content span { background-color: red; }")
106+
..flushGET('template.html').respond(200,
107+
'<span><content></content></span>');
127108

128109
try {
129110
document.body.append(element);
@@ -147,25 +128,23 @@ main() {
147128
xit('should style into child shadow dom with ::shadow.',
148129
async((TestBed _, MockHttpBackend backend, WebPlatform platform) {
149130

150-
backend
151-
..expectGET('outer-style.css').respond(200, 'my-inner::shadow .foo {'
152-
'background-color: red; }')
153-
..expectGET('outer-html.html').respond(200,
154-
'<my-inner><span class="foo">foo</span></my-inner>');
155-
156-
157131
Element element = e('<my-outer></my-outer>');
158132

159133
_.compile(element);
160134

161-
microLeap();
135+
162136
backend
163-
..flush()
164-
..expectGET('inner-style.css').respond(200, '/* no style */')
165-
..expectGET('inner-html.html').respond(200,
166-
'<span class="foo"><content></content></span>');
137+
..flushGET('outer-style.css').respond(200,
138+
'my-inner::shadow .foo {background-color: red; }')
139+
..flushGET('outer-html.html').respond(200,
140+
'<my-inner><span class="foo">foo</span></my-inner>');
141+
167142
microLeap();
168-
backend.flush();
143+
144+
backend
145+
..flushGET('inner-style.css').respond(200, '/* no style */')
146+
..flushGET('inner-html.html').respond(200,
147+
'<span class="foo"><content></content></span>');
169148

170149
try {
171150
document.body.append(element);

0 commit comments

Comments
 (0)