fix(testing): remove the `toThrowErrorWith` matcher (jasmine has `toThrowError`)

BREAKING CHANGE:

Before:

    expect(...).toThrowErrorWith(msg);

After:

    expect(...).toThrowError(msg);
This commit is contained in:
Victor Berchet 2016-06-22 14:58:57 -07:00
parent 6420f75320
commit e1e5c40ef7
17 changed files with 86 additions and 162 deletions

View File

@ -141,16 +141,14 @@ export function main() {
var dir = new NgControlName(form, null, null, [defaultAccessor]); var dir = new NgControlName(form, null, null, [defaultAccessor]);
dir.name = 'invalidName'; dir.name = 'invalidName';
expect(() => form.addControl(dir)) expect(() => form.addControl(dir)).toThrowError(/Cannot find control 'invalidName'/);
.toThrowError(new RegExp('Cannot find control \'invalidName\''));
}); });
it('should throw when no value accessor', () => { it('should throw when no value accessor', () => {
var dir = new NgControlName(form, null, null, null); var dir = new NgControlName(form, null, null, null);
dir.name = 'login'; dir.name = 'login';
expect(() => form.addControl(dir)) expect(() => form.addControl(dir)).toThrowError(/No value accessor for 'login'/);
.toThrowError(new RegExp('No value accessor for \'login\''));
}); });
it('should set up validators', fakeAsync(() => { it('should set up validators', fakeAsync(() => {

View File

@ -47,7 +47,7 @@ export function main() {
tcb.overrideTemplate(MyComp8, t).createAsync(MyComp8).then((fixture) => { tcb.overrideTemplate(MyComp8, t).createAsync(MyComp8).then((fixture) => {
expect(() => fixture.detectChanges()) expect(() => fixture.detectChanges())
.toThrowError(new RegExp(`ngFormModel expects a form. Please pass one in.`)); .toThrowError(/ngFormModel expects a form\. Please pass one in/);
async.done(); async.done();
}); });
})); }));

View File

@ -1,4 +1,4 @@
import {AST, BindingPipe, LiteralPrimitive} from '@angular/compiler/src/expression_parser/ast'; import {AST, BindingPipe} from '@angular/compiler/src/expression_parser/ast';
import {Lexer} from '@angular/compiler/src/expression_parser/lexer'; import {Lexer} from '@angular/compiler/src/expression_parser/lexer';
import {Parser} from '@angular/compiler/src/expression_parser/parser'; import {Parser} from '@angular/compiler/src/expression_parser/parser';
import {beforeEach, ddescribe, describe, expect, iit, it, xit} from '@angular/core/testing'; import {beforeEach, ddescribe, describe, expect, iit, it, xit} from '@angular/core/testing';
@ -10,26 +10,23 @@ import {Unparser} from './unparser';
export function main() { export function main() {
function createParser() { return new Parser(new Lexer()); } function createParser() { return new Parser(new Lexer()); }
function parseAction(text: any /** TODO #9100 */, location: any /** TODO #9100 */ = null): any { function parseAction(text: string, location: any = null): any {
return createParser().parseAction(text, location); return createParser().parseAction(text, location);
} }
function parseBinding(text: any /** TODO #9100 */, location: any /** TODO #9100 */ = null): any { function parseBinding(text: string, location: any = null): any {
return createParser().parseBinding(text, location); return createParser().parseBinding(text, location);
} }
function parseTemplateBindings( function parseTemplateBindings(text: string, location: any = null): any {
text: any /** TODO #9100 */, location: any /** TODO #9100 */ = null): any {
return createParser().parseTemplateBindings(text, location).templateBindings; return createParser().parseTemplateBindings(text, location).templateBindings;
} }
function parseInterpolation( function parseInterpolation(text: string, location: any = null): any {
text: any /** TODO #9100 */, location: any /** TODO #9100 */ = null): any {
return createParser().parseInterpolation(text, location); return createParser().parseInterpolation(text, location);
} }
function parseSimpleBinding( function parseSimpleBinding(text: string, location: any = null): any {
text: any /** TODO #9100 */, location: any /** TODO #9100 */ = null): any {
return createParser().parseSimpleBinding(text, location); return createParser().parseSimpleBinding(text, location);
} }
@ -135,10 +132,8 @@ export function main() {
}); });
it('should only allow identifier, string, or keyword as map key', () => { it('should only allow identifier, string, or keyword as map key', () => {
expectActionError('{(:0}').toThrowError( expectActionError('{(:0}').toThrowError(/expected identifier, keyword, or string/);
new RegExp('expected identifier, keyword, or string')); expectActionError('{1234:0}').toThrowError(/expected identifier, keyword, or string/);
expectActionError('{1234:0}')
.toThrowError(new RegExp('expected identifier, keyword, or string'));
}); });
}); });
@ -149,9 +144,9 @@ export function main() {
}); });
it('should only allow identifier or keyword as member names', () => { it('should only allow identifier or keyword as member names', () => {
expectActionError('x.(').toThrowError(new RegExp('identifier or keyword')); expectActionError('x.(').toThrowError(/identifier or keyword/);
expectActionError('x. 1234').toThrowError(new RegExp('identifier or keyword')); expectActionError('x. 1234').toThrowError(/identifier or keyword/);
expectActionError('x."foo"').toThrowError(new RegExp('identifier or keyword')); expectActionError('x."foo"').toThrowError(/identifier or keyword/);
}); });
it('should parse safe field access', () => { it('should parse safe field access', () => {
@ -180,8 +175,8 @@ export function main() {
}); });
it('should throw on incorrect ternary operator syntax', () => { it('should throw on incorrect ternary operator syntax', () => {
expectActionError('true?1').toThrowError(new RegExp( expectActionError('true?1').toThrowError(
'Parser Error: Conditional expression true\\?1 requires all 3 expressions')); /Parser Error: Conditional expression true\?1 requires all 3 expressions/);
}); });
}); });
@ -193,15 +188,14 @@ export function main() {
}); });
it('should throw on safe field assignments', () => { it('should throw on safe field assignments', () => {
expectActionError('a?.a = 123') expectActionError('a?.a = 123').toThrowError(/cannot be used in the assignment/);
.toThrowError(new RegExp('cannot be used in the assignment'));
}); });
it('should support array updates', () => { checkAction('a[0] = 200'); }); it('should support array updates', () => { checkAction('a[0] = 200'); });
}); });
it('should error when using pipes', it('should error when using pipes',
() => { expectActionError('x|blah').toThrowError(new RegExp('Cannot have a pipe')); }); () => { expectActionError('x|blah').toThrowError(/Cannot have a pipe/); });
it('should store the source in the result', it('should store the source in the result',
() => { expect(parseAction('someExpr').source).toBe('someExpr'); }); () => { expect(parseAction('someExpr').source).toBe('someExpr'); });
@ -210,24 +204,22 @@ export function main() {
() => { expect(parseAction('someExpr', 'location').location).toBe('location'); }); () => { expect(parseAction('someExpr', 'location').location).toBe('location'); });
it('should throw when encountering interpolation', () => { it('should throw when encountering interpolation', () => {
expectActionError('{{a()}}').toThrowErrorWith( expectActionError('{{a()}}').toThrowError(
'Got interpolation ({{}}) where expression was expected'); /Got interpolation \(\{\{\}\}\) where expression was expected/);
}); });
}); });
describe('general error handling', () => { describe('general error handling', () => {
it('should throw on an unexpected token', () => { it('should throw on an unexpected token',
expectActionError('[1,2] trac').toThrowError(new RegExp('Unexpected token \'trac\'')); () => { expectActionError('[1,2] trac').toThrowError(/Unexpected token \'trac\'/); });
});
it('should throw a reasonable error for unconsumed tokens', () => { it('should throw a reasonable error for unconsumed tokens', () => {
expectActionError(')').toThrowError( expectActionError(')').toThrowError(/Unexpected token \) at column 1 in \[\)\]/);
new RegExp('Unexpected token \\) at column 1 in \\[\\)\\]'));
}); });
it('should throw on missing expected token', () => { it('should throw on missing expected token', () => {
expectActionError('a(b').toThrowError( expectActionError('a(b').toThrowError(
new RegExp('Missing expected \\) at the end of the expression \\[a\\(b\\]')); /Missing expected \) at the end of the expression \[a\(b\]/);
}); });
}); });
@ -246,9 +238,9 @@ export function main() {
}); });
it('should only allow identifier or keyword as formatter names', () => { it('should only allow identifier or keyword as formatter names', () => {
expectBindingError('"Foo"|(').toThrowError(new RegExp('identifier or keyword')); expectBindingError('"Foo"|(').toThrowError(/identifier or keyword/);
expectBindingError('"Foo"|1234').toThrowError(new RegExp('identifier or keyword')); expectBindingError('"Foo"|1234').toThrowError(/identifier or keyword/);
expectBindingError('"Foo"|"uppercase"').toThrowError(new RegExp('identifier or keyword')); expectBindingError('"Foo"|"uppercase"').toThrowError(/identifier or keyword/);
}); });
it('should parse quoted expressions', () => { checkBinding('a:b', 'a:b'); }); it('should parse quoted expressions', () => { checkBinding('a:b', 'a:b'); });
@ -270,17 +262,15 @@ export function main() {
it('should store the passed-in location', it('should store the passed-in location',
() => { expect(parseBinding('someExpr', 'location').location).toBe('location'); }); () => { expect(parseBinding('someExpr', 'location').location).toBe('location'); });
it('should throw on chain expressions', () => { it('should throw on chain expressions',
expect(() => parseBinding('1;2')).toThrowError(new RegExp('contain chained expression')); () => { expect(() => parseBinding('1;2')).toThrowError(/contain chained expression/); });
});
it('should throw on assignment', () => { it('should throw on assignment',
expect(() => parseBinding('a=2')).toThrowError(new RegExp('contain assignments')); () => { expect(() => parseBinding('a=2')).toThrowError(/contain assignments/); });
});
it('should throw when encountering interpolation', () => { it('should throw when encountering interpolation', () => {
expectBindingError('{{a.b}}').toThrowErrorWith( expectBindingError('{{a.b}}').toThrowError(
'Got interpolation ({{}}) where expression was expected'); /Got interpolation \(\{\{\}\}\) where expression was expected/);
}); });
it('should parse conditional expression', () => { checkBinding('a < b ? a : b'); }); it('should parse conditional expression', () => { checkBinding('a < b ? a : b'); });
@ -335,11 +325,11 @@ export function main() {
expect(() => { expect(() => {
parseTemplateBindings('(:0'); parseTemplateBindings('(:0');
}).toThrowError(new RegExp('expected identifier, keyword, or string')); }).toThrowError(/expected identifier, keyword, or string/);
expect(() => { expect(() => {
parseTemplateBindings('1234:0'); parseTemplateBindings('1234:0');
}).toThrowError(new RegExp('expected identifier, keyword, or string')); }).toThrowError(/expected identifier, keyword, or string/);
}); });
it('should detect expressions as value', () => { it('should detect expressions as value', () => {
@ -452,12 +442,12 @@ export function main() {
it('should throw on empty interpolation expressions', () => { it('should throw on empty interpolation expressions', () => {
expect(() => parseInterpolation('{{}}')) expect(() => parseInterpolation('{{}}'))
.toThrowErrorWith( .toThrowError(
'Parser Error: Blank expressions are not allowed in interpolated strings'); /Parser Error: Blank expressions are not allowed in interpolated strings/);
expect(() => parseInterpolation('foo {{ }}')) expect(() => parseInterpolation('foo {{ }}'))
.toThrowErrorWith( .toThrowError(
'Parser Error: Blank expressions are not allowed in interpolated strings'); /Parser Error: Blank expressions are not allowed in interpolated strings/);
}); });
it('should parse conditional expression', it('should parse conditional expression',
@ -514,13 +504,12 @@ export function main() {
it('should throw when the given expression is not just a field name', () => { it('should throw when the given expression is not just a field name', () => {
expect(() => parseSimpleBinding('name + 1')) expect(() => parseSimpleBinding('name + 1'))
.toThrowErrorWith( .toThrowError(/Host binding expression can only contain field access and constants/);
'Host binding expression can only contain field access and constants');
}); });
it('should throw when encountering interpolation', () => { it('should throw when encountering interpolation', () => {
expect(() => parseSimpleBinding('{{exp}}')) expect(() => parseSimpleBinding('{{exp}}'))
.toThrowErrorWith('Got interpolation ({{}}) where expression was expected'); .toThrowError(/Got interpolation \(\{\{\}\}\) where expression was expected/);
}); });
}); });

View File

@ -711,8 +711,8 @@ export function main() {
it('should report missing @Self() deps as errors', () => { it('should report missing @Self() deps as errors', () => {
var dirA = createDir('[dirA]', {deps: ['self:provider0']}); var dirA = createDir('[dirA]', {deps: ['self:provider0']});
expect(() => parse('<div dirA></div>', [dirA])) expect(() => parse('<div dirA></div>', [dirA]))
.toThrowErrorWith( .toThrowError(
'No provider for provider0 ("[ERROR ->]<div dirA></div>"): TestComp@0:0'); 'Template parse errors:\nNo provider for provider0 ("[ERROR ->]<div dirA></div>"): TestComp@0:0');
}); });
it('should change missing @Self() that are optional to nulls', () => { it('should change missing @Self() that are optional to nulls', () => {
@ -725,8 +725,8 @@ export function main() {
it('should report missing @Host() deps as errors', () => { it('should report missing @Host() deps as errors', () => {
var dirA = createDir('[dirA]', {deps: ['host:provider0']}); var dirA = createDir('[dirA]', {deps: ['host:provider0']});
expect(() => parse('<div dirA></div>', [dirA])) expect(() => parse('<div dirA></div>', [dirA]))
.toThrowErrorWith( .toThrowError(
'No provider for provider0 ("[ERROR ->]<div dirA></div>"): TestComp@0:0'); 'Template parse errors:\nNo provider for provider0 ("[ERROR ->]<div dirA></div>"): TestComp@0:0');
}); });
it('should change missing @Host() that are optional to nulls', () => { it('should change missing @Host() that are optional to nulls', () => {
@ -1171,7 +1171,7 @@ Can't bind to 'invalidProp' since it isn't a known native property ("<div [ERROR
}); });
it('should report errors in expressions', () => { it('should report errors in expressions', () => {
expect(() => parse('<div [prop]="a b"></div>', [])).toThrowErrorWith(`Template parse errors: expect(() => parse('<div [prop]="a b"></div>', [])).toThrowError(`Template parse errors:
Parser Error: Unexpected token 'b' at column 3 in [a b] in TestComp@0:5 ("<div [ERROR ->][prop]="a b"></div>"): TestComp@0:5`); Parser Error: Unexpected token 'b' at column 3 in [a b] in TestComp@0:5 ("<div [ERROR ->][prop]="a b"></div>"): TestComp@0:5`);
}); });

View File

@ -40,13 +40,13 @@ export function main() {
it('should throw when Component has neither template nor templateUrl set', () => { it('should throw when Component has neither template nor templateUrl set', () => {
expect(() => resolver.resolve(ComponentWithoutView)) expect(() => resolver.resolve(ComponentWithoutView))
.toThrowErrorWith( .toThrowError(
'Component \'ComponentWithoutView\' must have either \'template\' or \'templateUrl\' set'); /Component 'ComponentWithoutView' must have either 'template' or 'templateUrl' set/);
}); });
it('should throw when simple class has no component decorator', () => { it('should throw when simple class has no component decorator', () => {
expect(() => resolver.resolve(SimpleClass)) expect(() => resolver.resolve(SimpleClass))
.toThrowErrorWith('Could not compile \'SimpleClass\' because it is not a component.'); .toThrowError('Could not compile \'SimpleClass\' because it is not a component.');
}); });
}); });
} }

View File

@ -309,7 +309,7 @@ export function main() {
}); });
it('should throw when given an invalid collection', () => { it('should throw when given an invalid collection', () => {
expect(() => differ.diff('invalid')).toThrowErrorWith('Error trying to diff \'invalid\''); expect(() => differ.diff('invalid')).toThrowError('Error trying to diff \'invalid\'');
}); });
}); });
}); });

View File

@ -203,8 +203,7 @@ export function main() {
}); });
it('should throw when given an invalid collection', () => { it('should throw when given an invalid collection', () => {
expect(() => differ.diff('invalid')) expect(() => differ.diff('invalid')).toThrowError('Error trying to diff \'invalid\'');
.toThrowErrorWith('Error trying to diff \'invalid\'');
}); });
}); });
} }

View File

@ -19,7 +19,7 @@ export function main() {
it('should throw when no suitable implementation found', () => { it('should throw when no suitable implementation found', () => {
var differs = new IterableDiffers([]); var differs = new IterableDiffers([]);
expect(() => differs.find('some object')) expect(() => differs.find('some object'))
.toThrowErrorWith('Cannot find a differ supporting object \'some object\'') .toThrowError(/Cannot find a differ supporting object 'some object'/);
}); });
it('should return the first suitable implementation', () => { it('should return the first suitable implementation', () => {
@ -46,7 +46,7 @@ export function main() {
var injector = ReflectiveInjector.resolveAndCreate([IterableDiffers.extend([])]); var injector = ReflectiveInjector.resolveAndCreate([IterableDiffers.extend([])]);
expect(() => injector.get(IterableDiffers)) expect(() => injector.get(IterableDiffers))
.toThrowErrorWith('Cannot extend IterableDiffers without a parent injector'); .toThrowError(/Cannot extend IterableDiffers without a parent injector/);
}); });
it('should extend di-inherited diffesr', () => { it('should extend di-inherited diffesr', () => {

View File

@ -65,10 +65,10 @@ class CyclicEngine {
} }
class NoAnnotations { class NoAnnotations {
constructor(secretDependency: any /** TODO #9100 */) {} constructor(secretDependency: any) {}
} }
function factoryFn(a: any /** TODO #9100 */) {} function factoryFn(a: any) {}
export function main() { export function main() {
var dynamicProviders = [ var dynamicProviders = [
@ -211,9 +211,8 @@ export function main() {
it('should support multiProviders', () => { it('should support multiProviders', () => {
var injector = createInjector([ var injector = createInjector([
Engine, Engine, {provide: Car, useClass: SportsCar, multi: true},
/* @ts2dart_Provider */ {provide: Car, useClass: SportsCar, multi: true}, {provide: Car, useClass: CarWithOptionalEngine, multi: true}
/* @ts2dart_Provider */ {provide: Car, useClass: CarWithOptionalEngine, multi: true}
]); ]);
var cars = injector.get(Car); var cars = injector.get(Car);
@ -223,10 +222,8 @@ export function main() {
}); });
it('should support multiProviders that are created using useExisting', () => { it('should support multiProviders that are created using useExisting', () => {
var injector = createInjector([ var injector = createInjector(
Engine, SportsCar, [Engine, SportsCar, {provide: Car, useExisting: SportsCar, multi: true}]);
/* @ts2dart_Provider */ {provide: Car, useExisting: SportsCar, multi: true}
]);
var cars = injector.get(Car); var cars = injector.get(Car);
expect(cars.length).toEqual(1); expect(cars.length).toEqual(1);
@ -488,8 +485,8 @@ export function main() {
it('should support multi providers', () => { it('should support multi providers', () => {
var provider = ReflectiveInjector.resolve([ var provider = ReflectiveInjector.resolve([
/* @ts2dart_Provider */ {provide: Engine, useClass: BrokenEngine, multi: true}, {provide: Engine, useClass: BrokenEngine, multi: true},
/* @ts2dart_Provider */ {provide: Engine, useClass: TurboEngine, multi: true} {provide: Engine, useClass: TurboEngine, multi: true}
])[0]; ])[0];
expect(provider.key.token).toBe(Engine); expect(provider.key.token).toBe(Engine);
@ -500,8 +497,8 @@ export function main() {
it('should support providers as hash', () => { it('should support providers as hash', () => {
var provider = ReflectiveInjector.resolve([ var provider = ReflectiveInjector.resolve([
/* @ts2dart_Provider */ {provide: Engine, useClass: BrokenEngine, multi: true}, {provide: Engine, useClass: BrokenEngine, multi: true},
/* @ts2dart_Provider */ {provide: Engine, useClass: TurboEngine, multi: true} {provide: Engine, useClass: TurboEngine, multi: true}
])[0]; ])[0];
expect(provider.key.token).toBe(Engine); expect(provider.key.token).toBe(Engine);
@ -510,9 +507,8 @@ export function main() {
}); });
it('should support multi providers with only one provider', () => { it('should support multi providers with only one provider', () => {
var provider = ReflectiveInjector.resolve([ var provider =
/* @ts2dart_Provider */ {provide: Engine, useClass: BrokenEngine, multi: true} ReflectiveInjector.resolve([{provide: Engine, useClass: BrokenEngine, multi: true}])[0];
])[0];
expect(provider.key.token).toBe(Engine); expect(provider.key.token).toBe(Engine);
expect(provider.multiProvider).toEqual(true); expect(provider.multiProvider).toEqual(true);
@ -521,17 +517,14 @@ export function main() {
it('should throw when mixing multi providers with regular providers', () => { it('should throw when mixing multi providers with regular providers', () => {
expect(() => { expect(() => {
ReflectiveInjector.resolve([ ReflectiveInjector.resolve(
/* @ts2dart_Provider */ {provide: Engine, useClass: BrokenEngine, multi: true}, Engine [{provide: Engine, useClass: BrokenEngine, multi: true}, Engine]);
]); }).toThrowError(/Cannot mix multi providers and regular providers/);
}).toThrowErrorWith('Cannot mix multi providers and regular providers');
expect(() => { expect(() => {
ReflectiveInjector.resolve([ ReflectiveInjector.resolve(
Engine, [Engine, {provide: Engine, useClass: BrokenEngine, multi: true}]);
/* @ts2dart_Provider */ {provide: Engine, useClass: BrokenEngine, multi: true} }).toThrowError(/Cannot mix multi providers and regular providers/);
]);
}).toThrowErrorWith('Cannot mix multi providers and regular providers');
}); });
it('should resolve forward references', () => { it('should resolve forward references', () => {
@ -570,16 +563,10 @@ export function main() {
}); });
it('should allow declaring dependencies with flat arrays', () => { it('should allow declaring dependencies with flat arrays', () => {
var resolved = ReflectiveInjector.resolve([{ var resolved = ReflectiveInjector.resolve(
provide: 'token', [{provide: 'token', useFactory: (e: any) => e, deps: [new InjectMetadata('dep')]}]);
useFactory: (e: any /** TODO #9100 */) => e, var nestedResolved = ReflectiveInjector.resolve(
deps: [new InjectMetadata('dep')] [{provide: 'token', useFactory: (e: any) => e, deps: [[new InjectMetadata('dep')]]}]);
}]);
var nestedResolved = ReflectiveInjector.resolve([{
provide: 'token',
useFactory: (e: any /** TODO #9100 */) => e,
deps: [[new InjectMetadata('dep')]]
}]);
expect(resolved[0].resolvedFactories[0].dependencies[0].key.token) expect(resolved[0].resolvedFactories[0].dependencies[0].key.token)
.toEqual(nestedResolved[0].resolvedFactories[0].dependencies[0].key.token); .toEqual(nestedResolved[0].resolvedFactories[0].dependencies[0].key.token);
}); });

View File

@ -110,7 +110,7 @@ function declareTests({useJit}: {useJit: boolean}) {
let ci = fixture.debugElement.componentInstance; let ci = fixture.debugElement.componentInstance;
ci.ctxProp = trusted; ci.ctxProp = trusted;
expect(() => fixture.detectChanges()) expect(() => fixture.detectChanges())
.toThrowErrorWith('Required a safe URL, got a Script'); .toThrowError(/Required a safe URL, got a Script/);
async.done(); async.done();
}); });

View File

@ -31,10 +31,6 @@ expect(element).toHaveCssStyle({width: '100px', height: 'auto'});
expect(exception).toContainError('Failed to load'); expect(exception).toContainError('Failed to load');
// #enddocregion // #enddocregion
// #docregion toThrowErrorWith
expect(() => { throw 'Failed to load'; }).toThrowErrorWith('Failed to load');
// #enddocregion
// #docregion toImplement // #docregion toImplement
expect(SomeClass).toImplement(OtherClass); expect(SomeClass).toImplement(OtherClass);
// #enddocregion // #enddocregion

View File

@ -27,7 +27,7 @@ export function main() {
setTemplateCache(null); setTemplateCache(null);
expect(() => { expect(() => {
xhr = new CachedXHR(); xhr = new CachedXHR();
}).toThrowErrorWith('CachedXHR: Template cache was not found in $templateCache.'); }).toThrowError('CachedXHR: Template cache was not found in $templateCache.');
}); });
it('should resolve the Promise with the cached file content on success', it('should resolve the Promise with the cached file content on success',

View File

@ -70,24 +70,6 @@ export interface NgMatchers extends jasmine.Matchers {
*/ */
toContainError(expected: any): boolean; toContainError(expected: any): boolean;
/**
* Expect a function to throw an error with the given error text when executed.
*
* ## Example
*
* {@example testing/ts/matchers.ts region='toThrowErrorWith'}
*/
toThrowErrorWith(expectedMessage: any): boolean;
/**
* Expect a string to match the given regular expression.
*
* ## Example
*
* {@example testing/ts/matchers.ts region='toMatchPattern'}
*/
toMatchPattern(expectedMessage: any): boolean;
/** /**
* Invert the matchers. * Invert the matchers.
*/ */
@ -233,26 +215,6 @@ _global.beforeEach(function() {
}; };
}, },
toThrowErrorWith: function() {
return {
compare: function(actual: any /** TODO #???? */, expectedText: any /** TODO #???? */) {
try {
actual();
return {
pass: false,
get message() { return 'Was expected to throw, but did not throw'; }
};
} catch (e) {
var errorMessage = e.toString();
return {
pass: errorMessage.indexOf(expectedText) > -1,
get message() { return 'Expected ' + errorMessage + ' to contain ' + expectedText; }
};
}
}
};
},
toImplement: function() { toImplement: function() {
return { return {
compare: function( compare: function(

View File

@ -1,17 +1,13 @@
import {beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal'; import {beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal';
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal'; import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing'; import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing';
import {Location} from '@angular/common'; import {Location} from '@angular/common';
import {NumberWrapper} from '../../src/facade/lang'; import {NumberWrapper, escapeRegExp} from '../../src/facade/lang';
import {PromiseWrapper} from '../../src/facade/async'; import {PromiseWrapper} from '../../src/facade/async';
import {ListWrapper} from '../../src/facade/collection'; import {ListWrapper} from '../../src/facade/collection';
import {Component} from '@angular/core';
import {provide, Component} from '@angular/core'; import {Router, RouteRegistry, RouterLink, AsyncRoute, AuxRoute, Route, RouteParams, RouteConfig, ROUTER_DIRECTIVES, ROUTER_PRIMARY_COMPONENT} from '@angular/router-deprecated';
import {Router, RouteRegistry, RouterLink, RouterOutlet, AsyncRoute, AuxRoute, Route, RouteParams, RouteConfig, ROUTER_DIRECTIVES, ROUTER_PRIMARY_COMPONENT} from '@angular/router-deprecated';
import {RootRouter} from '@angular/router-deprecated/src/router'; import {RootRouter} from '@angular/router-deprecated/src/router';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {By} from '@angular/platform-browser/src/dom/debug/by'; import {By} from '@angular/platform-browser/src/dom/debug/by';
import {SpyLocation} from '@angular/common/testing'; import {SpyLocation} from '@angular/common/testing';
@ -32,7 +28,7 @@ export function main() {
beforeEach(inject( beforeEach(inject(
[TestComponentBuilder, Router, Location], [TestComponentBuilder, Router, Location],
(tcBuilder: any /** TODO #9100 */, rtr: Router, loc: Location) => { (tcBuilder: TestComponentBuilder, rtr: Router, loc: Location) => {
tcb = tcBuilder; tcb = tcBuilder;
router = rtr; router = rtr;
location = loc; location = loc;
@ -138,8 +134,8 @@ export function main() {
.then((_) => { .then((_) => {
var link = ListWrapper.toJSON(['Book', {number: 100}]); var link = ListWrapper.toJSON(['Book', {number: 100}]);
expect(() => fixture.detectChanges()) expect(() => fixture.detectChanges())
.toThrowErrorWith( .toThrowError(new RegExp(escapeRegExp(
`Link "${link}" is ambiguous, use "./" or "../" to disambiguate.`); `Link "${link}" is ambiguous, use "./" or "../" to disambiguate.`)));
async.done(); async.done();
}); });
})); }));

View File

@ -262,7 +262,7 @@ export function main() {
RootHostCmp, new Route({path: '/first/...', component: DummyParentCmp, name: 'First'})); RootHostCmp, new Route({path: '/first/...', component: DummyParentCmp, name: 'First'}));
expect(() => { expect(() => {
registry.generate(['First'], []); registry.generate(['First'], []);
}).toThrowError('Link "["First"]" does not resolve to a terminal instruction.'); }).toThrowError(/Link "\["First"\]" does not resolve to a terminal instruction./);
}); });
it('should match matrix params on child components and query params on the root component', it('should match matrix params on child components and query params on the root component',

View File

@ -13,13 +13,12 @@ export function main() {
describe('errors', () => { describe('errors', () => {
it('should throw on missing selector', () => { it('should throw on missing selector', () => {
expect(() => getComponentInfo(AttributeNameComponent)) expect(() => getComponentInfo(AttributeNameComponent))
.toThrowErrorWith( .toThrowError('Only selectors matching element names are supported, got: [attr-name]');
'Only selectors matching element names are supported, got: [attr-name]');
}); });
it('should throw on non element names', () => { it('should throw on non element names', () => {
expect(() => getComponentInfo(NoAnnotationComponent)) expect(() => getComponentInfo(NoAnnotationComponent))
.toThrowErrorWith('No Directive annotation found on NoAnnotationComponent'); .toThrowError('No Directive annotation found on NoAnnotationComponent');
}); });
}); });

View File

@ -1632,8 +1632,6 @@ const PLATFORM_BROWSER_TESTING = [
'NgMatchers.toHaveCssStyle(expected:any):boolean', 'NgMatchers.toHaveCssStyle(expected:any):boolean',
'NgMatchers.toHaveText(expected:any):boolean', 'NgMatchers.toHaveText(expected:any):boolean',
'NgMatchers.toImplement(expected:any):boolean', 'NgMatchers.toImplement(expected:any):boolean',
'NgMatchers.toMatchPattern(expectedMessage:any):boolean',
'NgMatchers.toThrowErrorWith(expectedMessage:any):boolean',
'normalizeCSS(css:string):string', 'normalizeCSS(css:string):string',
'stringifyElement(el:any):string', 'stringifyElement(el:any):string',
'var browserDetection:BrowserDetection', 'var browserDetection:BrowserDetection',