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

Commit 5e25f1f

Browse files
committed
refactor(tests): change tests to use flushGET instead of expectGET
1 parent bf3cddc commit 5e25f1f

File tree

5 files changed

+77
-140
lines changed

5 files changed

+77
-140
lines changed

test/core/templateurl_spec.dart

+30-49
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,15 @@ void main() {
5858
Injector injector, VmTurnZone zone, MockHttpBackend backend,
5959
DirectiveMap directives) {
6060

61-
backend
62-
..whenGET('PREFIX:simple.html').respond('<div log="SIMPLE">Simple!</div>')
63-
..whenGET('PREFIX:simple.css').respond('.hello{}');
64-
6561
var element = e('<div><html-and-css log>ignore</html-and-css><div>');
6662
zone.run(() {
6763
compile([element], directives)(rootScope, null, [element]);
6864
});
6965

70-
backend.flush();
66+
backend
67+
..flushGET('PREFIX:simple.css').respond('.hello{}')
68+
..flushGET('PREFIX:simple.html').respond('<div log="SIMPLE">Simple!</div>');
69+
7170
microLeap();
7271

7372
expect(element).toHaveText('.hello{}Simple!');
@@ -91,13 +90,11 @@ void main() {
9190
it('should replace element with template from url', async(
9291
(Http http, Compiler compile, Scope rootScope, Logger log,
9392
Injector injector, MockHttpBackend backend, DirectiveMap directives) {
94-
backend.expectGET('simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
9593

9694
var element = es('<div><simple-url log>ignore</simple-url><div>');
9795
compile(element, directives)(rootScope, null, element);
9896

99-
microLeap();
100-
backend.flush();
97+
backend.flushGET('simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
10198
microLeap();
10299

103100
expect(element[0]).toHaveText('Simple!');
@@ -109,17 +106,14 @@ void main() {
109106
it('should load template from URL once', async(
110107
(Http http, Compiler compile, Scope rootScope, Logger log,
111108
Injector injector, MockHttpBackend backend, DirectiveMap directives) {
112-
backend.whenGET('simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
113-
114109
var element = es(
115110
'<div>'
116111
'<simple-url log>ignore</simple-url>'
117112
'<simple-url log>ignore</simple-url>'
118113
'<div>');
119114
compile(element, directives)(rootScope, null, element);
120115

121-
microLeap();
122-
backend.flush();
116+
backend.flushGET('simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
123117
microLeap();
124118

125119
expect(element.first).toHaveText('Simple!Simple!');
@@ -132,15 +126,13 @@ void main() {
132126
it('should load a CSS file into a style', async(
133127
(Http http, Compiler compile, Scope rootScope, Logger log,
134128
Injector injector, MockHttpBackend backend, DirectiveMap directives) {
135-
backend
136-
..expectGET('simple.css').respond(200, '.hello{}')
137-
..expectGET('simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
138-
139129
var element = e('<div><html-and-css log>ignore</html-and-css><div>');
140130
compile([element], directives)(rootScope, null, [element]);
141131

142-
microLeap();
143-
backend.flush();
132+
backend
133+
..flushGET('simple.css').respond(200, '.hello{}')
134+
..flushGET('simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
135+
144136
microLeap();
145137

146138
expect(element).toHaveText('.hello{}Simple!');
@@ -156,25 +148,23 @@ void main() {
156148
(Http http, Compiler compile, Scope rootScope, Injector injector,
157149
MockHttpBackend backend, DirectiveMap directives) {
158150
var element = es('<div><inline-with-css log>ignore</inline-with-css><div>');
159-
backend.expectGET('simple.css').respond(200, '.hello{}');
160-
compile(element, directives)(rootScope, null, element);
151+
compile(element, directives)(injector, element);
161152

153+
backend.flushGET('simple.css').respond(200, '.hello{}');
162154
microLeap();
163-
backend.flush();
164-
microLeap();
155+
165156
expect(element[0]).toHaveText('.hello{}inline!');
166157
}));
167158

168159
it('should ignore CSS load errors ', async(
169160
(Http http, Compiler compile, Scope rootScope, Injector injector,
170161
MockHttpBackend backend, DirectiveMap directives) {
171162
var element = es('<div><inline-with-css log>ignore</inline-with-css><div>');
172-
backend.expectGET('simple.css').respond(500, 'some error');
173-
compile(element, directives)(rootScope, null, element);
163+
compile(element, directives)(injector, element);
174164

165+
backend.flushGET('simple.css').respond(500, 'some error');
175166
microLeap();
176-
backend.flush();
177-
microLeap();
167+
178168
expect(element.first).toHaveText(
179169
'/*\n'
180170
'HTTP 500: some error\n'
@@ -186,28 +176,25 @@ void main() {
186176
(Http http, Compiler compile, Scope rootScope, Injector injector,
187177
MockHttpBackend backend, DirectiveMap directives) {
188178
var element = es('<div><only-css log>ignore</only-css><div>');
189-
backend.expectGET('simple.css').respond(200, '.hello{}');
190-
compile(element, directives)(rootScope, null, element);
179+
compile(element, directives)(injector, element);
191180

181+
backend.flushGET('simple.css').respond(200, '.hello{}');
192182
microLeap();
193-
backend.flush();
194-
microLeap();
183+
195184
expect(element[0]).toHaveText('.hello{}');
196185
}));
197186

198187
it('should load the CSS before the template is loaded', async(
199188
(Http http, Compiler compile, Scope rootScope, Injector injector,
200189
MockHttpBackend backend, DirectiveMap directives) {
201-
backend
202-
..expectGET('simple.css').respond(200, '.hello{}')
203-
..expectGET('simple.html').respond(200, '<div>Simple!</div>');
204-
205190
var element = es('<html-and-css>ignore</html-and-css>');
206191
compile(element, directives)(rootScope, null, element);
207192

193+
backend
194+
..flushGET('simple.css').respond(200, '.hello{}')
195+
..flushGET('simple.html').respond(200, '<div>Simple!</div>');
208196
microLeap();
209-
backend.flush();
210-
microLeap();
197+
211198
expect(element.first).toHaveText('.hello{}Simple!');
212199
}));
213200
});
@@ -222,16 +209,13 @@ void main() {
222209
it('should load multiple CSS files into a style', async(
223210
(Http http, Compiler compile, Scope rootScope, Logger log,
224211
Injector injector, MockHttpBackend backend, DirectiveMap directives) {
225-
backend
226-
..expectGET('simple.css').respond(200, '.hello{}')
227-
..expectGET('another.css').respond(200, '.world{}')
228-
..expectGET('simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
229-
230212
var element = e('<div><html-and-css log>ignore</html-and-css><div>');
231213
compile([element], directives)(rootScope, null, [element]);
232214

233-
microLeap();
234-
backend.flush();
215+
backend
216+
..flushGET('simple.css').respond(200, '.hello{}')
217+
..flushGET('another.css').respond(200, '.world{}')
218+
..flushGET('simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
235219
microLeap();
236220

237221
expect(element).toHaveText('.hello{}.world{}Simple!');
@@ -254,15 +238,12 @@ void main() {
254238
it('should load css from the style cache for the second component', async(
255239
(Http http, Compiler compile, MockHttpBackend backend, RootScope rootScope,
256240
DirectiveMap directives, Injector injector) {
257-
backend
258-
..expectGET('simple.css').respond(200, '.hello{}')
259-
..expectGET('simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
260-
261241
var element = e('<div><html-and-css>ignore</html-and-css><div>');
262242
compile([element], directives)(rootScope, null, [element]);
263243

264-
microLeap();
265-
backend.flush();
244+
backend
245+
..flushGET('simple.css').respond(200, '.hello{}')
246+
..flushGET('simple.html').respond(200, '<div log="SIMPLE">Simple!</div>');
266247
microLeap();
267248

268249
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).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('style.css').respond(200, 'span { background-color: red; '
24-
'}')
25-
..expectGET('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('style.css').respond(200, 'span {background-color: red;}')
29+
..flushGET('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('style.css').respond(200, 'span { background-color: red; '
63-
'}')
64-
..expectGET('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('style.css').respond(200, 'span{background-color: red}')
63+
..flushGET('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('style.css').respond(200, ':host {'
81-
'background-color: red; }')
82-
..expectGET('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('style.css').respond(200, ':host {background-color: red; }')
76+
..flushGET('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)