@@ -6,6 +6,11 @@ import {MdInputModule} from './input';
6
6
import { MdInputContainer } from './input-container' ;
7
7
import { MdPlatform } from '../core/platform/platform' ;
8
8
import { PlatformModule } from '../core/platform/index' ;
9
+ import {
10
+ MdInputContainerMissingMdInputError ,
11
+ MdInputContainerPlaceholderConflictError ,
12
+ MdInputContainerDuplicatedHintError
13
+ } from './input-container-errors' ;
9
14
10
15
11
16
describe ( 'MdInputContainer' , function ( ) {
@@ -35,6 +40,7 @@ describe('MdInputContainer', function () {
35
40
MdInputContainerNumberTestController ,
36
41
MdTextareaWithBindings ,
37
42
MdInputContainerWithDisabled ,
43
+ MdInputContainerMissingMdInputTestController
38
44
] ,
39
45
} ) ;
40
46
@@ -150,25 +156,29 @@ describe('MdInputContainer', function () {
150
156
it ( 'validates there\'s only one hint label per side' , ( ) => {
151
157
let fixture = TestBed . createComponent ( MdInputContainerInvalidHintTestController ) ;
152
158
153
- expect ( ( ) => fixture . detectChanges ( ) ) . toThrow ( ) ;
154
- // TODO(jelbourn): .toThrow(new MdInputContainerDuplicatedHintError('start'));
155
- // See https://github.com/angular/angular/issues/8348
159
+ expect ( ( ) => fixture . detectChanges ( ) ) . toThrowError (
160
+ angularWrappedErrorMessage ( new MdInputContainerDuplicatedHintError ( 'start' ) ) ) ;
156
161
} ) ;
157
162
158
163
it ( 'validates there\'s only one hint label per side (attribute)' , ( ) => {
159
164
let fixture = TestBed . createComponent ( MdInputContainerInvalidHint2TestController ) ;
160
165
161
- expect ( ( ) => fixture . detectChanges ( ) ) . toThrow ( ) ;
162
- // TODO(jelbourn): .toThrow(new MdInputContainerDuplicatedHintError('start'));
163
- // See https://github.com/angular/angular/issues/8348
166
+ expect ( ( ) => fixture . detectChanges ( ) ) . toThrowError (
167
+ angularWrappedErrorMessage ( new MdInputContainerDuplicatedHintError ( 'start' ) ) ) ;
164
168
} ) ;
165
169
166
170
it ( 'validates there\'s only one placeholder' , ( ) => {
167
171
let fixture = TestBed . createComponent ( MdInputContainerInvalidPlaceholderTestController ) ;
168
172
169
- expect ( ( ) => fixture . detectChanges ( ) ) . toThrow ( ) ;
170
- // TODO(jelbourn): .toThrow(new MdInputContainerPlaceholderConflictError());
171
- // See https://github.com/angular/angular/issues/8348
173
+ expect ( ( ) => fixture . detectChanges ( ) ) . toThrowError (
174
+ angularWrappedErrorMessage ( new MdInputContainerPlaceholderConflictError ( ) ) ) ;
175
+ } ) ;
176
+
177
+ it ( 'validates that md-input child is present' , ( ) => {
178
+ let fixture = TestBed . createComponent ( MdInputContainerMissingMdInputTestController ) ;
179
+
180
+ expect ( ( ) => fixture . detectChanges ( ) ) . toThrowError (
181
+ angularWrappedErrorMessage ( new MdInputContainerMissingMdInputError ( ) ) ) ;
172
182
} ) ;
173
183
174
184
it ( 'validates the type' , ( ) => {
@@ -406,3 +416,21 @@ class MdTextareaWithBindings {
406
416
cols : number = 8 ;
407
417
wrap : string = 'hard' ;
408
418
}
419
+
420
+ @Component ( {
421
+ template : `<md-input-container><input></md-input-container>`
422
+ } )
423
+ class MdInputContainerMissingMdInputTestController { }
424
+
425
+ /**
426
+ * Gets a RegExp used to detect an angular wrapped error message.
427
+ * See https://github.com/angular/angular/issues/8348
428
+ */
429
+ const angularWrappedErrorMessage = ( e : Error ) =>
430
+ new RegExp ( `.*caused by: ${ regexpEscape ( e . message ) } $` ) ;
431
+
432
+ /**
433
+ * Escape a string for use inside a RegExp.
434
+ * Based on https://github.com/sindresorhus/escape-string-regex
435
+ */
436
+ const regexpEscape = ( s : string ) => s . replace ( / [ | \\ { } ( ) [ \] ^ $ + * ? . ] / g, '\\$&' ) ;
0 commit comments