1
1
// Based on https://github.com/angular/angular/blob/master/modules/angular2/test/testing/testing_public_spec.ts
2
2
/* tslint:disable */
3
3
import {
4
- BadTemplateUrl , ButtonComp ,
4
+ ButtonComp ,
5
5
ChildChildComp , ChildComp , ChildWithChildComp ,
6
6
ExternalTemplateComp ,
7
7
FancyService , MockFancyService ,
@@ -16,62 +16,19 @@ import { DebugElement } from '@angular/core';
16
16
import { By } from '@angular/platform-browser' ;
17
17
18
18
import {
19
- beforeEach , beforeEachProviders ,
20
- describe , ddescribe , xdescribe ,
21
- expect , it , iit , xit ,
22
- async , inject ,
19
+ addProviders ,
20
+ inject , async ,
23
21
fakeAsync , tick , withProviders
24
22
} from '@angular/core/testing' ;
25
23
26
- import { ComponentFixture , TestComponentBuilder } from '@angular/compiler /testing' ;
24
+ import { ComponentFixture , TestComponentBuilder } from '@angular/core /testing' ;
27
25
28
26
import { ViewMetadata } from '@angular/core' ;
29
27
30
28
import { Observable } from 'rxjs/Rx' ;
31
29
32
30
//////// SPECS /////////////
33
31
34
- /// Verify can use Angular testing's DOM abstraction to access DOM
35
-
36
- describe ( 'angular2 jasmine matchers' , ( ) => {
37
- describe ( 'toHaveCssClass' , ( ) => {
38
- it ( 'should assert that the CSS class is present' , ( ) => {
39
- let el = document . createElement ( 'div' ) ;
40
- el . classList . add ( 'bombasto' ) ;
41
- expect ( el ) . toHaveCssClass ( 'bombasto' ) ;
42
- } ) ;
43
-
44
- it ( 'should assert that the CSS class is not present' , ( ) => {
45
- let el = document . createElement ( 'div' ) ;
46
- el . classList . add ( 'bombasto' ) ;
47
- expect ( el ) . not . toHaveCssClass ( 'fatias' ) ;
48
- } ) ;
49
- } ) ;
50
-
51
- describe ( 'toHaveCssStyle' , ( ) => {
52
- it ( 'should assert that the CSS style is present' , ( ) => {
53
- let el = document . createElement ( 'div' ) ;
54
- expect ( el ) . not . toHaveCssStyle ( 'width' ) ;
55
-
56
- el . style . setProperty ( 'width' , '100px' ) ;
57
- expect ( el ) . toHaveCssStyle ( 'width' ) ;
58
- } ) ;
59
-
60
- it ( 'should assert that the styles are matched against the element' , ( ) => {
61
- let el = document . createElement ( 'div' ) ;
62
- expect ( el ) . not . toHaveCssStyle ( { width : '100px' , height : '555px' } ) ;
63
-
64
- el . style . setProperty ( 'width' , '100px' ) ;
65
- expect ( el ) . toHaveCssStyle ( { width : '100px' } ) ;
66
- expect ( el ) . not . toHaveCssStyle ( { width : '100px' , height : '555px' } ) ;
67
-
68
- el . style . setProperty ( 'height' , '555px' ) ;
69
- expect ( el ) . toHaveCssStyle ( { height : '555px' } ) ;
70
- expect ( el ) . toHaveCssStyle ( { width : '100px' , height : '555px' } ) ;
71
- } ) ;
72
- } ) ;
73
- } ) ;
74
-
75
32
describe ( 'using the async helper' , ( ) => {
76
33
let actuallyDone = false ;
77
34
@@ -101,7 +58,7 @@ describe('using the async helper', () => {
101
58
p . catch ( ( ) => { actuallyDone = true ; } ) ;
102
59
} ) ) ;
103
60
104
- it ( 'should run async test with successful Observable' , async ( ( ) => {
61
+ xit ( 'should run async test with successful Observable' , async ( ( ) => {
105
62
let source = Observable . of ( true ) . delay ( 10 ) ;
106
63
source . subscribe (
107
64
val => { } ,
@@ -114,9 +71,11 @@ describe('using the async helper', () => {
114
71
describe ( 'using the test injector with the inject helper' , ( ) => {
115
72
116
73
describe ( 'setting up Providers with FancyService' , ( ) => {
117
- beforeEachProviders ( ( ) => [
118
- { provide : FancyService , useValue : new FancyService ( ) }
119
- ] ) ;
74
+ beforeEach ( ( ) => {
75
+ addProviders ( [
76
+ { provide : FancyService , useValue : new FancyService ( ) }
77
+ ] ) ;
78
+ } ) ;
120
79
121
80
it ( 'should use FancyService' ,
122
81
inject ( [ FancyService ] , ( service : FancyService ) => {
@@ -142,7 +101,7 @@ describe('using the test injector with the inject helper', () => {
142
101
) ;
143
102
} ) ) ) ;
144
103
145
- it ( 'test should wait for FancyService.getObservableDelayValue' ,
104
+ xit ( 'test should wait for FancyService.getObservableDelayValue' ,
146
105
async ( inject ( [ FancyService ] , ( service : FancyService ) => {
147
106
service . getObservableDelayValue ( ) . subscribe (
148
107
value => { expect ( value ) . toEqual ( 'observable delay value' ) ; }
@@ -197,7 +156,7 @@ describe('test component builder', function() {
197
156
198
157
tcb . createAsync ( ChildComp ) . then ( fixture => {
199
158
fixture . detectChanges ( ) ;
200
- expect ( fixture . nativeElement ) . toHaveText ( 'Original Child' ) ;
159
+ expect ( fixture . nativeElement . textContent ) . toContain ( 'Original Child' ) ;
201
160
} ) ;
202
161
} ) ) ) ;
203
162
@@ -206,11 +165,11 @@ describe('test component builder', function() {
206
165
207
166
tcb . createAsync ( MyIfComp ) . then ( fixture => {
208
167
fixture . detectChanges ( ) ;
209
- expect ( fixture . nativeElement ) . toHaveText ( 'MyIf()' ) ;
168
+ expect ( fixture . nativeElement . textContent ) . toContain ( 'MyIf()' ) ;
210
169
211
170
fixture . debugElement . componentInstance . showMore = true ;
212
171
fixture . detectChanges ( ) ;
213
- expect ( fixture . nativeElement ) . toHaveText ( 'MyIf(More)' ) ;
172
+ expect ( fixture . nativeElement . textContent ) . toContain ( 'MyIf(More)' ) ;
214
173
} ) ;
215
174
} ) ) ) ;
216
175
@@ -262,7 +221,7 @@ describe('test component builder', function() {
262
221
. createAsync ( MockChildComp )
263
222
. then ( fixture => {
264
223
fixture . detectChanges ( ) ;
265
- expect ( fixture . nativeElement ) . toHaveText ( 'Mock' ) ;
224
+ expect ( fixture . nativeElement . textContent ) . toContain ( 'Mock' ) ;
266
225
} ) ;
267
226
} ) ) ) ;
268
227
@@ -276,7 +235,7 @@ describe('test component builder', function() {
276
235
. createAsync ( ChildComp )
277
236
. then ( fixture => {
278
237
fixture . detectChanges ( ) ;
279
- expect ( fixture . nativeElement ) . toHaveText ( 'Modified Child' ) ;
238
+ expect ( fixture . nativeElement . textContent ) . toContain ( 'Modified Child' ) ;
280
239
281
240
} ) ;
282
241
} ) ) ) ;
@@ -288,7 +247,7 @@ describe('test component builder', function() {
288
247
. createAsync ( ParentComp )
289
248
. then ( fixture => {
290
249
fixture . detectChanges ( ) ;
291
- expect ( fixture . nativeElement ) . toHaveText ( 'Parent(Mock)' ) ;
250
+ expect ( fixture . nativeElement . textContent ) . toContain ( 'Parent(Mock)' ) ;
292
251
293
252
} ) ;
294
253
} ) ) ) ;
@@ -302,8 +261,8 @@ describe('test component builder', function() {
302
261
. createAsync ( ParentComp )
303
262
. then ( fixture => {
304
263
fixture . detectChanges ( ) ;
305
- expect ( fixture . nativeElement )
306
- . toHaveText ( 'Parent(Original Child(ChildChild Mock))' ) ;
264
+ expect ( fixture . nativeElement . textContent )
265
+ . toContain ( 'Parent(Original Child(ChildChild Mock))' ) ;
307
266
308
267
} ) ;
309
268
} ) ) ) ;
@@ -318,8 +277,8 @@ describe('test component builder', function() {
318
277
. createAsync ( TestProvidersComp )
319
278
. then ( fixture => {
320
279
fixture . detectChanges ( ) ;
321
- expect ( fixture . nativeElement )
322
- . toHaveText ( 'injected value: mocked out value' ) ;
280
+ expect ( fixture . nativeElement . textContent )
281
+ . toContain ( 'injected value: mocked out value' ) ;
323
282
} ) ;
324
283
} ) ) ) ;
325
284
@@ -333,8 +292,8 @@ describe('test component builder', function() {
333
292
. createAsync ( TestViewProvidersComp )
334
293
. then ( fixture => {
335
294
fixture . detectChanges ( ) ;
336
- expect ( fixture . nativeElement )
337
- . toHaveText ( 'injected value: mocked out value' ) ;
295
+ expect ( fixture . nativeElement . textContent )
296
+ . toContain ( 'injected value: mocked out value' ) ;
338
297
} ) ;
339
298
} ) ) ) ;
340
299
@@ -344,8 +303,8 @@ describe('test component builder', function() {
344
303
tcb . createAsync ( ExternalTemplateComp )
345
304
. then ( fixture => {
346
305
fixture . detectChanges ( ) ;
347
- expect ( fixture . nativeElement )
348
- . toHaveText ( 'from external template\n' ) ;
306
+ expect ( fixture . nativeElement . textContent )
307
+ . toContain ( 'from external template\n' ) ;
349
308
} ) ;
350
309
} ) ) , 10000 ) ; // Long timeout because this test makes an actual XHR.
351
310
0 commit comments