chore(format): update to latest formatter

Closes #7958
This commit is contained in:
Alex Eagle
2016-04-07 17:17:50 -07:00
committed by Alex Eagle
parent 83b8f59297
commit 03627aa84d
527 changed files with 13975 additions and 19252 deletions
@@ -1,19 +1,4 @@
import {
ComponentFixture,
AsyncTestCompleter,
TestComponentBuilder,
beforeEach,
beforeEachProviders,
ddescribe,
xdescribe,
describe,
el,
expect,
iit,
inject,
it,
xit,
} from 'angular2/testing_internal';
import {ComponentFixture, AsyncTestCompleter, TestComponentBuilder, beforeEach, beforeEachProviders, ddescribe, xdescribe, describe, el, expect, iit, inject, it, xit,} from 'angular2/testing_internal';
import {ListWrapper, StringMapWrapper, SetWrapper} from 'angular2/src/facade/collection';
import {Component, provide} from 'angular2/core';
import {NgFor} from 'angular2/common';
@@ -1,17 +1,4 @@
import {
AsyncTestCompleter,
TestComponentBuilder,
beforeEach,
beforeEachProviders,
ddescribe,
describe,
el,
expect,
iit,
inject,
it,
xit,
} from 'angular2/testing_internal';
import {AsyncTestCompleter, TestComponentBuilder, beforeEach, beforeEachProviders, ddescribe, describe, el, expect, iit, inject, it, xit,} from 'angular2/testing_internal';
import {ListWrapper} from 'angular2/src/facade/collection';
import {IS_DART} from 'angular2/src/facade/lang';
@@ -162,18 +149,16 @@ export function main() {
if (!IS_DART) {
it('should throw on non-iterable ref and suggest using an array',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(TestComponent, TEMPLATE)
.createAsync(TestComponent)
.then((fixture) => {
fixture.debugElement.componentInstance.items = 'whaaa';
try {
fixture.detectChanges()
} catch (e) {
expect(e.message).toContain(
`Cannot find a differ supporting object 'whaaa' of type 'string'. NgFor only supports binding to Iterables such as Arrays.`);
async.done();
}
});
tcb.overrideTemplate(TestComponent, TEMPLATE).createAsync(TestComponent).then((fixture) => {
fixture.debugElement.componentInstance.items = 'whaaa';
try {
fixture.detectChanges()
} catch (e) {
expect(e.message).toContain(
`Cannot find a differ supporting object 'whaaa' of type 'string'. NgFor only supports binding to Iterables such as Arrays.`);
async.done();
}
});
}));
}
@@ -207,12 +192,12 @@ export function main() {
it('should repeat over nested arrays',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template = '<div>' +
'<div template="ngFor #item of items">' +
'<div template="ngFor #subitem of item">' +
'{{subitem}}-{{item.length}};' +
'</div>|' +
'</div>' +
'</div>';
'<div template="ngFor #item of items">' +
'<div template="ngFor #subitem of item">' +
'{{subitem}}-{{item.length}};' +
'</div>|' +
'</div>' +
'</div>';
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
@@ -234,9 +219,9 @@ export function main() {
it('should repeat over nested arrays with no intermediate element',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template = '<div><template ngFor #item [ngForOf]="items">' +
'<div template="ngFor #subitem of item">' +
'{{subitem}}-{{item.length}};' +
'</div></template></div>';
'<div template="ngFor #subitem of item">' +
'{{subitem}}-{{item.length}};' +
'</div></template></div>';
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
@@ -1,16 +1,4 @@
import {
AsyncTestCompleter,
TestComponentBuilder,
beforeEach,
ddescribe,
describe,
el,
expect,
iit,
inject,
it,
xit,
} from 'angular2/testing_internal';
import {AsyncTestCompleter, TestComponentBuilder, beforeEach, ddescribe, describe, el, expect, iit, inject, it, xit,} from 'angular2/testing_internal';
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
@@ -25,15 +13,13 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var html = '<div><copy-me template="ngIf booleanCondition">hello</copy-me></div>';
tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent)
.then((fixture) => {
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('hello');
async.done();
});
tcb.overrideTemplate(TestComponent, html).createAsync(TestComponent).then((fixture) => {
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('hello');
async.done();
});
}));
it('should work in a template element',
@@ -41,44 +27,40 @@ export function main() {
var html =
'<div><template [ngIf]="booleanCondition"><copy-me>hello2</copy-me></template></div>';
tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent)
.then((fixture) => {
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('hello2');
async.done();
});
tcb.overrideTemplate(TestComponent, html).createAsync(TestComponent).then((fixture) => {
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('hello2');
async.done();
});
}));
it('should toggle node when condition changes',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var html = '<div><copy-me template="ngIf booleanCondition">hello</copy-me></div>';
tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent)
.then((fixture) => {
fixture.debugElement.componentInstance.booleanCondition = false;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(0);
expect(fixture.debugElement.nativeElement).toHaveText('');
tcb.overrideTemplate(TestComponent, html).createAsync(TestComponent).then((fixture) => {
fixture.debugElement.componentInstance.booleanCondition = false;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(0);
expect(fixture.debugElement.nativeElement).toHaveText('');
fixture.debugElement.componentInstance.booleanCondition = true;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('hello');
fixture.debugElement.componentInstance.booleanCondition = true;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('hello');
fixture.debugElement.componentInstance.booleanCondition = false;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(0);
expect(fixture.debugElement.nativeElement).toHaveText('');
fixture.debugElement.componentInstance.booleanCondition = false;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(0);
expect(fixture.debugElement.nativeElement).toHaveText('');
async.done();
});
async.done();
});
}));
it('should handle nested if correctly',
@@ -86,75 +68,70 @@ export function main() {
var html =
'<div><template [ngIf]="booleanCondition"><copy-me *ngIf="nestedBooleanCondition">hello</copy-me></template></div>';
tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent)
.then((fixture) => {
fixture.debugElement.componentInstance.booleanCondition = false;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(0);
expect(fixture.debugElement.nativeElement).toHaveText('');
tcb.overrideTemplate(TestComponent, html).createAsync(TestComponent).then((fixture) => {
fixture.debugElement.componentInstance.booleanCondition = false;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(0);
expect(fixture.debugElement.nativeElement).toHaveText('');
fixture.debugElement.componentInstance.booleanCondition = true;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('hello');
fixture.debugElement.componentInstance.booleanCondition = true;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('hello');
fixture.debugElement.componentInstance.nestedBooleanCondition = false;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(0);
expect(fixture.debugElement.nativeElement).toHaveText('');
fixture.debugElement.componentInstance.nestedBooleanCondition = false;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(0);
expect(fixture.debugElement.nativeElement).toHaveText('');
fixture.debugElement.componentInstance.nestedBooleanCondition = true;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('hello');
fixture.debugElement.componentInstance.nestedBooleanCondition = true;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('hello');
fixture.debugElement.componentInstance.booleanCondition = false;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(0);
expect(fixture.debugElement.nativeElement).toHaveText('');
fixture.debugElement.componentInstance.booleanCondition = false;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(0);
expect(fixture.debugElement.nativeElement).toHaveText('');
async.done();
});
async.done();
});
}));
it('should update several nodes with if',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var html =
'<div>' +
var html = '<div>' +
'<copy-me template="ngIf numberCondition + 1 >= 2">helloNumber</copy-me>' +
'<copy-me template="ngIf stringCondition == \'foo\'">helloString</copy-me>' +
'<copy-me template="ngIf functionCondition(stringCondition, numberCondition)">helloFunction</copy-me>' +
'</div>';
tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent)
.then((fixture) => {
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(3);
expect(DOM.getText(fixture.debugElement.nativeElement))
.toEqual('helloNumberhelloStringhelloFunction');
tcb.overrideTemplate(TestComponent, html).createAsync(TestComponent).then((fixture) => {
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(3);
expect(DOM.getText(fixture.debugElement.nativeElement))
.toEqual('helloNumberhelloStringhelloFunction');
fixture.debugElement.componentInstance.numberCondition = 0;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('helloString');
fixture.debugElement.componentInstance.numberCondition = 0;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('helloString');
fixture.debugElement.componentInstance.numberCondition = 1;
fixture.debugElement.componentInstance.stringCondition = "bar";
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('helloNumber');
async.done();
});
fixture.debugElement.componentInstance.numberCondition = 1;
fixture.debugElement.componentInstance.stringCondition = 'bar';
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('helloNumber');
async.done();
});
}));
@@ -163,44 +140,38 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var html = '<div><copy-me template="ngIf numberCondition">hello</copy-me></div>';
tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent)
.then((fixture) => {
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('hello');
tcb.overrideTemplate(TestComponent, html).createAsync(TestComponent).then((fixture) => {
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('hello');
fixture.debugElement.componentInstance.numberCondition = 2;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('hello');
fixture.debugElement.componentInstance.numberCondition = 2;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(fixture.debugElement.nativeElement).toHaveText('hello');
async.done();
});
async.done();
});
}));
it('should not recreate the element if the condition goes from true to true (JS)',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var html = '<div><copy-me template="ngIf numberCondition">hello</copy-me></div>';
tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent)
.then((fixture) => {
fixture.detectChanges();
DOM.addClass(DOM.querySelector(fixture.debugElement.nativeElement, 'copy-me'),
"foo");
tcb.overrideTemplate(TestComponent, html).createAsync(TestComponent).then((fixture) => {
fixture.detectChanges();
DOM.addClass(DOM.querySelector(fixture.debugElement.nativeElement, 'copy-me'), 'foo');
fixture.debugElement.componentInstance.numberCondition = 2;
fixture.detectChanges();
expect(
DOM.hasClass(DOM.querySelector(fixture.debugElement.nativeElement, 'copy-me'),
"foo"))
.toBe(true);
fixture.debugElement.componentInstance.numberCondition = 2;
fixture.detectChanges();
expect(DOM.hasClass(
DOM.querySelector(fixture.debugElement.nativeElement, 'copy-me'), 'foo'))
.toBe(true);
async.done();
});
async.done();
});
}));
}
@@ -209,15 +180,13 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var html = '<div><copy-me template="ngIf numberCondition">hello</copy-me></div>';
tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent)
.then((fixture) => {
expect(() => fixture.detectChanges()).toThrowError();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(0);
expect(fixture.debugElement.nativeElement).toHaveText('');
async.done();
});
tcb.overrideTemplate(TestComponent, html).createAsync(TestComponent).then((fixture) => {
expect(() => fixture.detectChanges()).toThrowError();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(0);
expect(fixture.debugElement.nativeElement).toHaveText('');
async.done();
});
}));
}
@@ -235,7 +204,7 @@ class TestComponent {
this.booleanCondition = true;
this.nestedBooleanCondition = true;
this.numberCondition = 1;
this.stringCondition = "foo";
this.functionCondition = function(s, n) { return s == "foo" && n == 1; };
this.stringCondition = 'foo';
this.functionCondition = function(s, n) { return s == 'foo' && n == 1; };
}
}
@@ -1,17 +1,4 @@
import {
AsyncTestCompleter,
TestComponentBuilder,
beforeEachProviders,
beforeEach,
ddescribe,
describe,
el,
expect,
iit,
inject,
it,
xit,
} from 'angular2/testing_internal';
import {AsyncTestCompleter, TestComponentBuilder, beforeEachProviders, beforeEach, ddescribe, describe, el, expect, iit, inject, it, xit,} from 'angular2/testing_internal';
import {Component, Injectable, provide} from 'angular2/core';
import {NgPlural, NgPluralCase, NgLocalization} from 'angular2/common';
@@ -23,10 +10,10 @@ export function main() {
it('should display the template according to the exact value',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template = '<div>' +
'<ul [ngPlural]="switchValue">' +
'<template ngPluralCase="=0"><li>you have no messages.</li></template>' +
'<template ngPluralCase="=1"><li>you have one message.</li></template>' +
'</ul></div>';
'<ul [ngPlural]="switchValue">' +
'<template ngPluralCase="=0"><li>you have no messages.</li></template>' +
'<template ngPluralCase="=1"><li>you have one message.</li></template>' +
'</ul></div>';
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
@@ -45,8 +32,7 @@ export function main() {
it('should display the template according to the category',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template =
'<div>' +
var template = '<div>' +
'<ul [ngPlural]="switchValue">' +
'<template ngPluralCase="few"><li>you have a few messages.</li></template>' +
'<template ngPluralCase="many"><li>you have many messages.</li></template>' +
@@ -69,8 +55,7 @@ export function main() {
it('should default to other when no matches are found',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template =
'<div>' +
var template = '<div>' +
'<ul [ngPlural]="switchValue">' +
'<template ngPluralCase="few"><li>you have a few messages.</li></template>' +
'<template ngPluralCase="other"><li>default message.</li></template>' +
@@ -89,8 +74,7 @@ export function main() {
it('should prioritize value matches over category matches',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template =
'<div>' +
var template = '<div>' +
'<ul [ngPlural]="switchValue">' +
'<template ngPluralCase="few"><li>you have a few messages.</li></template>' +
'<template ngPluralCase="=2">you have two messages.</template>' +
@@ -1,18 +1,4 @@
import {
AsyncTestCompleter,
TestComponentBuilder,
beforeEach,
beforeEachProviders,
ddescribe,
xdescribe,
describe,
el,
expect,
iit,
inject,
it,
xit,
} from 'angular2/testing_internal';
import {AsyncTestCompleter, TestComponentBuilder, beforeEach, beforeEachProviders, ddescribe, xdescribe, describe, el, expect, iit, inject, it, xit,} from 'angular2/testing_internal';
import {StringMapWrapper} from 'angular2/src/facade/collection';
@@ -1,16 +1,4 @@
import {
AsyncTestCompleter,
TestComponentBuilder,
beforeEach,
ddescribe,
describe,
el,
expect,
iit,
inject,
it,
xit,
} from 'angular2/testing_internal';
import {AsyncTestCompleter, TestComponentBuilder, beforeEach, ddescribe, describe, el, expect, iit, inject, it, xit,} from 'angular2/testing_internal';
import {Component} from 'angular2/core';
@@ -22,10 +10,10 @@ export function main() {
it('should switch amongst when values',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template = '<div>' +
'<ul [ngSwitch]="switchValue">' +
'<template ngSwitchWhen="a"><li>when a</li></template>' +
'<template ngSwitchWhen="b"><li>when b</li></template>' +
'</ul></div>';
'<ul [ngSwitch]="switchValue">' +
'<template ngSwitchWhen="a"><li>when a</li></template>' +
'<template ngSwitchWhen="b"><li>when b</li></template>' +
'</ul></div>';
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
@@ -48,10 +36,10 @@ export function main() {
it('should switch amongst when values with fallback to default',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template = '<div>' +
'<ul [ngSwitch]="switchValue">' +
'<li template="ngSwitchWhen \'a\'">when a</li>' +
'<li template="ngSwitchDefault">when default</li>' +
'</ul></div>';
'<ul [ngSwitch]="switchValue">' +
'<li template="ngSwitchWhen \'a\'">when a</li>' +
'<li template="ngSwitchDefault">when default</li>' +
'</ul></div>';
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
@@ -74,14 +62,14 @@ export function main() {
it('should support multiple whens with the same value',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template = '<div>' +
'<ul [ngSwitch]="switchValue">' +
'<template ngSwitchWhen="a"><li>when a1;</li></template>' +
'<template ngSwitchWhen="b"><li>when b1;</li></template>' +
'<template ngSwitchWhen="a"><li>when a2;</li></template>' +
'<template ngSwitchWhen="b"><li>when b2;</li></template>' +
'<template ngSwitchDefault><li>when default1;</li></template>' +
'<template ngSwitchDefault><li>when default2;</li></template>' +
'</ul></div>';
'<ul [ngSwitch]="switchValue">' +
'<template ngSwitchWhen="a"><li>when a1;</li></template>' +
'<template ngSwitchWhen="b"><li>when b1;</li></template>' +
'<template ngSwitchWhen="a"><li>when a2;</li></template>' +
'<template ngSwitchWhen="b"><li>when b2;</li></template>' +
'<template ngSwitchDefault><li>when default1;</li></template>' +
'<template ngSwitchDefault><li>when default2;</li></template>' +
'</ul></div>';
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
@@ -107,11 +95,11 @@ export function main() {
it('should switch amongst when values',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template = '<div>' +
'<ul [ngSwitch]="switchValue">' +
'<template [ngSwitchWhen]="when1"><li>when 1;</li></template>' +
'<template [ngSwitchWhen]="when2"><li>when 2;</li></template>' +
'<template ngSwitchDefault><li>when default;</li></template>' +
'</ul></div>';
'<ul [ngSwitch]="switchValue">' +
'<template [ngSwitchWhen]="when1"><li>when 1;</li></template>' +
'<template [ngSwitchWhen]="when2"><li>when 2;</li></template>' +
'<template ngSwitchDefault><li>when default;</li></template>' +
'</ul></div>';
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
@@ -1,16 +1,4 @@
import {
AsyncTestCompleter,
TestComponentBuilder,
beforeEach,
ddescribe,
describe,
el,
expect,
iit,
inject,
it,
xit,
} from 'angular2/testing_internal';
import {AsyncTestCompleter, TestComponentBuilder, beforeEach, ddescribe, describe, el, expect, iit, inject, it, xit,} from 'angular2/testing_internal';
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
import {Component, Directive} from 'angular2/core';
import {ElementRef} from 'angular2/src/core/linker/element_ref';
@@ -1,41 +1,10 @@
import {
ddescribe,
describe,
fakeAsync,
flushMicrotasks,
it,
iit,
xit,
expect,
beforeEach,
afterEach,
el,
AsyncTestCompleter,
inject,
tick
} from 'angular2/testing_internal';
import {ddescribe, describe, fakeAsync, flushMicrotasks, it, iit, xit, expect, beforeEach, afterEach, el, AsyncTestCompleter, inject, tick} from 'angular2/testing_internal';
import {SpyNgControl, SpyValueAccessor} from '../spies';
import {QueryList} from 'angular2/core';
import {
ControlGroup,
Control,
NgControlName,
NgControlGroup,
NgFormModel,
ControlValueAccessor,
Validators,
NgForm,
NgModel,
NgFormControl,
NgControl,
DefaultValueAccessor,
CheckboxControlValueAccessor,
SelectControlValueAccessor,
Validator
} from 'angular2/common';
import {ControlGroup, Control, NgControlName, NgControlGroup, NgFormModel, ControlValueAccessor, Validators, NgForm, NgModel, NgFormControl, NgControl, DefaultValueAccessor, CheckboxControlValueAccessor, SelectControlValueAccessor, Validator} from 'angular2/common';
import {selectValueAccessor, composeValidators} from 'angular2/src/common/forms/directives/shared';
@@ -53,13 +22,13 @@ class DummyControlValueAccessor implements ControlValueAccessor {
}
class CustomValidatorDirective implements Validator {
validate(c: Control): {[key: string]: any} { return {"custom": true}; }
validate(c: Control): {[key: string]: any} { return {'custom': true}; }
}
function asyncValidator(expected, timeout = 0) {
return (c) => {
var completer = PromiseWrapper.completer();
var res = c.value != expected ? {"async": true} : null;
var res = c.value != expected ? {'async': true} : null;
if (timeout == 0) {
completer.resolve(res);
} else {
@@ -70,71 +39,74 @@ function asyncValidator(expected, timeout = 0) {
}
export function main() {
describe("Form Directives", () => {
describe('Form Directives', () => {
var defaultAccessor;
beforeEach(() => { defaultAccessor = new DefaultValueAccessor(null, null); });
describe("shared", () => {
describe("selectValueAccessor", () => {
describe('shared', () => {
describe('selectValueAccessor', () => {
var dir: NgControl;
beforeEach(() => { dir = <any>new SpyNgControl(); });
it("should throw when given an empty array",
it('should throw when given an empty array',
() => { expect(() => selectValueAccessor(dir, [])).toThrowError(); });
it("should return the default value accessor when no other provided",
it('should return the default value accessor when no other provided',
() => { expect(selectValueAccessor(dir, [defaultAccessor])).toEqual(defaultAccessor); });
it("should return checkbox accessor when provided", () => {
it('should return checkbox accessor when provided', () => {
var checkboxAccessor = new CheckboxControlValueAccessor(null, null);
expect(selectValueAccessor(dir, [defaultAccessor, checkboxAccessor]))
.toEqual(checkboxAccessor);
expect(selectValueAccessor(dir, [
defaultAccessor, checkboxAccessor
])).toEqual(checkboxAccessor);
});
it("should return select accessor when provided", () => {
it('should return select accessor when provided', () => {
var selectAccessor = new SelectControlValueAccessor(null, null);
expect(selectValueAccessor(dir, [defaultAccessor, selectAccessor]))
.toEqual(selectAccessor);
expect(selectValueAccessor(dir, [
defaultAccessor, selectAccessor
])).toEqual(selectAccessor);
});
it("should throw when more than one build-in accessor is provided", () => {
it('should throw when more than one build-in accessor is provided', () => {
var checkboxAccessor = new CheckboxControlValueAccessor(null, null);
var selectAccessor = new SelectControlValueAccessor(null, null);
expect(() => selectValueAccessor(dir, [checkboxAccessor, selectAccessor])).toThrowError();
});
it("should return custom accessor when provided", () => {
it('should return custom accessor when provided', () => {
var customAccessor = new SpyValueAccessor();
var checkboxAccessor = new CheckboxControlValueAccessor(null, null);
expect(selectValueAccessor(dir, [defaultAccessor, customAccessor, checkboxAccessor]))
.toEqual(customAccessor);
expect(selectValueAccessor(dir, [
defaultAccessor, customAccessor, checkboxAccessor
])).toEqual(customAccessor);
});
it("should throw when more than one custom accessor is provided", () => {
it('should throw when more than one custom accessor is provided', () => {
var customAccessor: ControlValueAccessor = <any>new SpyValueAccessor();
expect(() => selectValueAccessor(dir, [customAccessor, customAccessor])).toThrowError();
});
});
describe("composeValidators", () => {
it("should compose functions", () => {
var dummy1 = (_) => ({"dummy1": true});
var dummy2 = (_) => ({"dummy2": true});
describe('composeValidators', () => {
it('should compose functions', () => {
var dummy1 = (_) => ({'dummy1': true});
var dummy2 = (_) => ({'dummy2': true});
var v = composeValidators([dummy1, dummy2]);
expect(v(new Control(""))).toEqual({"dummy1": true, "dummy2": true});
expect(v(new Control(''))).toEqual({'dummy1': true, 'dummy2': true});
});
it("should compose validator directives", () => {
var dummy1 = (_) => ({"dummy1": true});
it('should compose validator directives', () => {
var dummy1 = (_) => ({'dummy1': true});
var v = composeValidators([dummy1, new CustomValidatorDirective()]);
expect(v(new Control(""))).toEqual({"dummy1": true, "custom": true});
expect(v(new Control(''))).toEqual({'dummy1': true, 'custom': true});
});
});
});
describe("NgFormModel", () => {
describe('NgFormModel', () => {
var form;
var formModel: ControlGroup;
var loginControlDir;
@@ -142,19 +114,19 @@ export function main() {
beforeEach(() => {
form = new NgFormModel([], []);
formModel = new ControlGroup({
"login": new Control(),
"passwords":
new ControlGroup({"password": new Control(), "passwordConfirm": new Control()})
'login': new Control(),
'passwords':
new ControlGroup({'password': new Control(), 'passwordConfirm': new Control()})
});
form.form = formModel;
loginControlDir = new NgControlName(form, [Validators.required],
[asyncValidator("expected")], [defaultAccessor]);
loginControlDir.name = "login";
loginControlDir = new NgControlName(
form, [Validators.required], [asyncValidator('expected')], [defaultAccessor]);
loginControlDir.name = 'login';
loginControlDir.valueAccessor = new DummyControlValueAccessor();
});
it("should reexport control properties", () => {
it('should reexport control properties', () => {
expect(form.control).toBe(formModel);
expect(form.value).toBe(formModel.value);
expect(form.valid).toBe(formModel.valid);
@@ -165,130 +137,132 @@ export function main() {
expect(form.untouched).toBe(formModel.untouched);
});
describe("addControl", () => {
it("should throw when no control found", () => {
describe('addControl', () => {
it('should throw when no control found', () => {
var dir = new NgControlName(form, null, null, [defaultAccessor]);
dir.name = "invalidName";
dir.name = 'invalidName';
expect(() => form.addControl(dir))
.toThrowError(new RegExp("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);
dir.name = "login";
dir.name = 'login';
expect(() => form.addControl(dir))
.toThrowError(new RegExp("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(() => {
form.addControl(loginControlDir);
// sync validators are set
expect(formModel.hasError("required", ["login"])).toBe(true);
expect(formModel.hasError("async", ["login"])).toBe(false);
expect(formModel.hasError('required', ['login'])).toBe(true);
expect(formModel.hasError('async', ['login'])).toBe(false);
(<Control>formModel.find(["login"])).updateValue("invalid value");
(<Control>formModel.find(['login'])).updateValue('invalid value');
// sync validator passes, running async validators
expect(formModel.pending).toBe(true);
tick();
expect(formModel.hasError("required", ["login"])).toBe(false);
expect(formModel.hasError("async", ["login"])).toBe(true);
expect(formModel.hasError('required', ['login'])).toBe(false);
expect(formModel.hasError('async', ['login'])).toBe(true);
}));
it("should write value to the DOM", () => {
(<Control>formModel.find(["login"])).updateValue("initValue");
it('should write value to the DOM', () => {
(<Control>formModel.find(['login'])).updateValue('initValue');
form.addControl(loginControlDir);
expect((<any>loginControlDir.valueAccessor).writtenValue).toEqual("initValue");
expect((<any>loginControlDir.valueAccessor).writtenValue).toEqual('initValue');
});
it("should add the directive to the list of directives included in the form", () => {
it('should add the directive to the list of directives included in the form', () => {
form.addControl(loginControlDir);
expect(form.directives).toEqual([loginControlDir]);
});
});
describe("addControlGroup", () => {
describe('addControlGroup', () => {
var matchingPasswordsValidator = (g) => {
if (g.controls["password"].value != g.controls["passwordConfirm"].value) {
return {"differentPasswords": true};
if (g.controls['password'].value != g.controls['passwordConfirm'].value) {
return {'differentPasswords': true};
} else {
return null;
}
};
it("should set up validator", fakeAsync(() => {
var group = new NgControlGroup(form, [matchingPasswordsValidator],
[asyncValidator('expected')]);
group.name = "passwords";
it('should set up validator', fakeAsync(() => {
var group = new NgControlGroup(
form, [matchingPasswordsValidator], [asyncValidator('expected')]);
group.name = 'passwords';
form.addControlGroup(group);
(<Control>formModel.find(["passwords", "password"])).updateValue("somePassword");
(<Control>formModel.find(["passwords", "passwordConfirm"]))
.updateValue("someOtherPassword");
(<Control>formModel.find(['passwords', 'password'])).updateValue('somePassword');
(<Control>formModel.find([
'passwords', 'passwordConfirm'
])).updateValue('someOtherPassword');
// sync validators are set
expect(formModel.hasError("differentPasswords", ["passwords"])).toEqual(true);
expect(formModel.hasError('differentPasswords', ['passwords'])).toEqual(true);
(<Control>formModel.find(["passwords", "passwordConfirm"]))
.updateValue("somePassword");
(<Control>formModel.find([
'passwords', 'passwordConfirm'
])).updateValue('somePassword');
// sync validators pass, running async validators
expect(formModel.pending).toBe(true);
tick();
expect(formModel.hasError("async", ["passwords"])).toBe(true);
expect(formModel.hasError('async', ['passwords'])).toBe(true);
}));
});
describe("removeControl", () => {
it("should remove the directive to the list of directives included in the form", () => {
describe('removeControl', () => {
it('should remove the directive to the list of directives included in the form', () => {
form.addControl(loginControlDir);
form.removeControl(loginControlDir);
expect(form.directives).toEqual([]);
});
});
describe("ngOnChanges", () => {
it("should update dom values of all the directives", () => {
describe('ngOnChanges', () => {
it('should update dom values of all the directives', () => {
form.addControl(loginControlDir);
(<Control>formModel.find(["login"])).updateValue("new value");
(<Control>formModel.find(['login'])).updateValue('new value');
form.ngOnChanges({});
expect((<any>loginControlDir.valueAccessor).writtenValue).toEqual("new value");
expect((<any>loginControlDir.valueAccessor).writtenValue).toEqual('new value');
});
it("should set up a sync validator", () => {
var formValidator = (c) => ({"custom": true});
it('should set up a sync validator', () => {
var formValidator = (c) => ({'custom': true});
var f = new NgFormModel([formValidator], []);
f.form = formModel;
f.ngOnChanges({"form": new SimpleChange(null, null)});
f.ngOnChanges({'form': new SimpleChange(null, null)});
expect(formModel.errors).toEqual({"custom": true});
expect(formModel.errors).toEqual({'custom': true});
});
it("should set up an async validator", fakeAsync(() => {
var f = new NgFormModel([], [asyncValidator("expected")]);
it('should set up an async validator', fakeAsync(() => {
var f = new NgFormModel([], [asyncValidator('expected')]);
f.form = formModel;
f.ngOnChanges({"form": new SimpleChange(null, null)});
f.ngOnChanges({'form': new SimpleChange(null, null)});
tick();
expect(formModel.errors).toEqual({"async": true});
expect(formModel.errors).toEqual({'async': true});
}));
});
});
describe("NgForm", () => {
describe('NgForm', () => {
var form;
var formModel: ControlGroup;
var loginControlDir;
@@ -299,14 +273,14 @@ export function main() {
formModel = form.form;
personControlGroupDir = new NgControlGroup(form, [], []);
personControlGroupDir.name = "person";
personControlGroupDir.name = 'person';
loginControlDir = new NgControlName(personControlGroupDir, null, null, [defaultAccessor]);
loginControlDir.name = "login";
loginControlDir.name = 'login';
loginControlDir.valueAccessor = new DummyControlValueAccessor();
});
it("should reexport control properties", () => {
it('should reexport control properties', () => {
expect(form.control).toBe(formModel);
expect(form.value).toBe(formModel.value);
expect(form.valid).toBe(formModel.valid);
@@ -317,21 +291,21 @@ export function main() {
expect(form.untouched).toBe(formModel.untouched);
});
describe("addControl & addControlGroup", () => {
it("should create a control with the given name", fakeAsync(() => {
describe('addControl & addControlGroup', () => {
it('should create a control with the given name', fakeAsync(() => {
form.addControlGroup(personControlGroupDir);
form.addControl(loginControlDir);
flushMicrotasks();
expect(formModel.find(["person", "login"])).not.toBeNull;
expect(formModel.find(['person', 'login'])).not.toBeNull;
}));
// should update the form's value and validity
});
describe("removeControl & removeControlGroup", () => {
it("should remove control", fakeAsync(() => {
describe('removeControl & removeControlGroup', () => {
it('should remove control', fakeAsync(() => {
form.addControlGroup(personControlGroupDir);
form.addControl(loginControlDir);
@@ -340,45 +314,45 @@ export function main() {
flushMicrotasks();
expect(formModel.find(["person"])).toBeNull();
expect(formModel.find(["person", "login"])).toBeNull();
expect(formModel.find(['person'])).toBeNull();
expect(formModel.find(['person', 'login'])).toBeNull();
}));
// should update the form's value and validity
});
it("should set up sync validator", fakeAsync(() => {
var formValidator = (c) => ({"custom": true});
it('should set up sync validator', fakeAsync(() => {
var formValidator = (c) => ({'custom': true});
var f = new NgForm([formValidator], []);
tick();
expect(f.form.errors).toEqual({"custom": true});
expect(f.form.errors).toEqual({'custom': true});
}));
it("should set up async validator", fakeAsync(() => {
var f = new NgForm([], [asyncValidator("expected")]);
it('should set up async validator', fakeAsync(() => {
var f = new NgForm([], [asyncValidator('expected')]);
tick();
expect(f.form.errors).toEqual({"async": true});
expect(f.form.errors).toEqual({'async': true});
}));
});
describe("NgControlGroup", () => {
describe('NgControlGroup', () => {
var formModel;
var controlGroupDir;
beforeEach(() => {
formModel = new ControlGroup({"login": new Control(null)});
formModel = new ControlGroup({'login': new Control(null)});
var parent = new NgFormModel([], []);
parent.form = new ControlGroup({"group": formModel});
parent.form = new ControlGroup({'group': formModel});
controlGroupDir = new NgControlGroup(parent, [], []);
controlGroupDir.name = "group";
controlGroupDir.name = 'group';
});
it("should reexport control properties", () => {
it('should reexport control properties', () => {
expect(controlGroupDir.control).toBe(formModel);
expect(controlGroupDir.value).toBe(formModel.value);
expect(controlGroupDir.valid).toBe(formModel.valid);
@@ -390,7 +364,7 @@ export function main() {
});
});
describe("NgFormControl", () => {
describe('NgFormControl', () => {
var controlDir;
var control;
var checkProperties = function(control) {
@@ -412,36 +386,36 @@ export function main() {
controlDir.form = control;
});
it("should reexport control properties", () => { checkProperties(control); });
it('should reexport control properties', () => { checkProperties(control); });
it("should reexport new control properties", () => {
it('should reexport new control properties', () => {
var newControl = new Control(null);
controlDir.form = newControl;
controlDir.ngOnChanges({"form": new SimpleChange(control, newControl)});
controlDir.ngOnChanges({'form': new SimpleChange(control, newControl)});
checkProperties(newControl);
});
it("should set up validator", () => {
it('should set up validator', () => {
expect(control.valid).toBe(true);
// this will add the required validator and recalculate the validity
controlDir.ngOnChanges({"form": new SimpleChange(null, control)});
controlDir.ngOnChanges({'form': new SimpleChange(null, control)});
expect(control.valid).toBe(false);
});
});
describe("NgModel", () => {
describe('NgModel', () => {
var ngModel;
beforeEach(() => {
ngModel =
new NgModel([Validators.required], [asyncValidator("expected")], [defaultAccessor]);
new NgModel([Validators.required], [asyncValidator('expected')], [defaultAccessor]);
ngModel.valueAccessor = new DummyControlValueAccessor();
});
it("should reexport control properties", () => {
it('should reexport control properties', () => {
var control = ngModel.control;
expect(ngModel.control).toBe(control);
expect(ngModel.value).toBe(control.value);
@@ -453,34 +427,34 @@ export function main() {
expect(ngModel.untouched).toBe(control.untouched);
});
it("should set up validator", fakeAsync(() => {
it('should set up validator', fakeAsync(() => {
// this will add the required validator and recalculate the validity
ngModel.ngOnChanges({});
tick();
expect(ngModel.control.errors).toEqual({"required": true});
expect(ngModel.control.errors).toEqual({'required': true});
ngModel.control.updateValue("someValue");
ngModel.control.updateValue('someValue');
tick();
expect(ngModel.control.errors).toEqual({"async": true});
expect(ngModel.control.errors).toEqual({'async': true});
}));
});
describe("NgControlName", () => {
describe('NgControlName', () => {
var formModel;
var controlNameDir;
beforeEach(() => {
formModel = new Control("name");
formModel = new Control('name');
var parent = new NgFormModel([], []);
parent.form = new ControlGroup({"name": formModel});
parent.form = new ControlGroup({'name': formModel});
controlNameDir = new NgControlName(parent, [], [], [defaultAccessor]);
controlNameDir.name = "name";
controlNameDir.name = 'name';
});
it("should reexport control properties", () => {
it('should reexport control properties', () => {
expect(controlNameDir.control).toBe(formModel);
expect(controlNameDir.value).toBe(formModel.value);
expect(controlNameDir.valid).toBe(formModel.valid);
@@ -1,14 +1,4 @@
import {
ddescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach,
el
} from 'angular2/testing_internal';
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, el} from 'angular2/testing_internal';
import {Control, FormBuilder} from 'angular2/common';
import {PromiseWrapper} from 'angular2/src/facade/promise';
@@ -16,53 +6,53 @@ export function main() {
function syncValidator(_) { return null; }
function asyncValidator(_) { return PromiseWrapper.resolve(null); }
describe("Form Builder", () => {
describe('Form Builder', () => {
var b;
beforeEach(() => { b = new FormBuilder(); });
it("should create controls from a value", () => {
var g = b.group({"login": "some value"});
it('should create controls from a value', () => {
var g = b.group({'login': 'some value'});
expect(g.controls["login"].value).toEqual("some value");
expect(g.controls['login'].value).toEqual('some value');
});
it("should create controls from an array", () => {
it('should create controls from an array', () => {
var g = b.group(
{"login": ["some value"], "password": ["some value", syncValidator, asyncValidator]});
{'login': ['some value'], 'password': ['some value', syncValidator, asyncValidator]});
expect(g.controls["login"].value).toEqual("some value");
expect(g.controls["password"].value).toEqual("some value");
expect(g.controls["password"].validator).toEqual(syncValidator);
expect(g.controls["password"].asyncValidator).toEqual(asyncValidator);
expect(g.controls['login'].value).toEqual('some value');
expect(g.controls['password'].value).toEqual('some value');
expect(g.controls['password'].validator).toEqual(syncValidator);
expect(g.controls['password'].asyncValidator).toEqual(asyncValidator);
});
it("should use controls", () => {
var g = b.group({"login": b.control("some value", syncValidator, asyncValidator)});
it('should use controls', () => {
var g = b.group({'login': b.control('some value', syncValidator, asyncValidator)});
expect(g.controls["login"].value).toEqual("some value");
expect(g.controls["login"].validator).toBe(syncValidator);
expect(g.controls["login"].asyncValidator).toBe(asyncValidator);
expect(g.controls['login'].value).toEqual('some value');
expect(g.controls['login'].validator).toBe(syncValidator);
expect(g.controls['login'].asyncValidator).toBe(asyncValidator);
});
it("should create groups with optional controls", () => {
var g = b.group({"login": "some value"}, {"optionals": {"login": false}});
it('should create groups with optional controls', () => {
var g = b.group({'login': 'some value'}, {'optionals': {'login': false}});
expect(g.contains("login")).toEqual(false);
expect(g.contains('login')).toEqual(false);
});
it("should create groups with a custom validator", () => {
var g = b.group({"login": "some value"},
{"validator": syncValidator, "asyncValidator": asyncValidator});
it('should create groups with a custom validator', () => {
var g = b.group(
{'login': 'some value'}, {'validator': syncValidator, 'asyncValidator': asyncValidator});
expect(g.validator).toBe(syncValidator);
expect(g.asyncValidator).toBe(asyncValidator);
});
it("should create control arrays", () => {
var c = b.control("three");
var a = b.array(["one", ["two", syncValidator], c, b.array(['four'])], syncValidator,
asyncValidator);
it('should create control arrays', () => {
var c = b.control('three');
var a = b.array(
['one', ['two', syncValidator], c, b.array(['four'])], syncValidator, asyncValidator);
expect(a.value).toEqual(['one', 'two', 'three', ['four']]);
expect(a.validator).toBe(syncValidator);
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,16 +1,4 @@
import {
ddescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach,
fakeAsync,
tick,
el
} from 'angular2/testing_internal';
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, fakeAsync, tick, el} from 'angular2/testing_internal';
import {ControlGroup, Control, Validators, AbstractControl, ControlArray} from 'angular2/common';
import {PromiseWrapper} from 'angular2/src/facade/promise';
import {EventEmitter, ObservableWrapper, TimerWrapper} from 'angular2/src/facade/async';
@@ -25,95 +13,98 @@ export function main() {
}
}
describe("Validators", () => {
describe("required", () => {
it("should error on an empty string",
() => { expect(Validators.required(new Control(""))).toEqual({"required": true}); });
describe('Validators', () => {
describe('required', () => {
it('should error on an empty string',
() => { expect(Validators.required(new Control(''))).toEqual({'required': true}); });
it("should error on null",
() => { expect(Validators.required(new Control(null))).toEqual({"required": true}); });
it('should error on null',
() => { expect(Validators.required(new Control(null))).toEqual({'required': true}); });
it("should not error on a non-empty string",
() => { expect(Validators.required(new Control("not empty"))).toEqual(null); });
it('should not error on a non-empty string',
() => { expect(Validators.required(new Control('not empty'))).toEqual(null); });
it("should accept zero as valid",
it('should accept zero as valid',
() => { expect(Validators.required(new Control(0))).toEqual(null); });
});
describe("minLength", () => {
it("should not error on an empty string",
() => { expect(Validators.minLength(2)(new Control(""))).toEqual(null); });
describe('minLength', () => {
it('should not error on an empty string',
() => { expect(Validators.minLength(2)(new Control(''))).toEqual(null); });
it("should not error on null",
it('should not error on null',
() => { expect(Validators.minLength(2)(new Control(null))).toEqual(null); });
it("should not error on valid strings",
() => { expect(Validators.minLength(2)(new Control("aa"))).toEqual(null); });
it('should not error on valid strings',
() => { expect(Validators.minLength(2)(new Control('aa'))).toEqual(null); });
it("should error on short strings", () => {
expect(Validators.minLength(2)(new Control("a")))
.toEqual({"minlength": {"requiredLength": 2, "actualLength": 1}});
it('should error on short strings', () => {
expect(Validators.minLength(2)(new Control('a'))).toEqual({
'minlength': {'requiredLength': 2, 'actualLength': 1}
});
});
});
describe("maxLength", () => {
it("should not error on an empty string",
() => { expect(Validators.maxLength(2)(new Control(""))).toEqual(null); });
describe('maxLength', () => {
it('should not error on an empty string',
() => { expect(Validators.maxLength(2)(new Control(''))).toEqual(null); });
it("should not error on null",
it('should not error on null',
() => { expect(Validators.maxLength(2)(new Control(null))).toEqual(null); });
it("should not error on valid strings",
() => { expect(Validators.maxLength(2)(new Control("aa"))).toEqual(null); });
it('should not error on valid strings',
() => { expect(Validators.maxLength(2)(new Control('aa'))).toEqual(null); });
it("should error on long strings", () => {
expect(Validators.maxLength(2)(new Control("aaa")))
.toEqual({"maxlength": {"requiredLength": 2, "actualLength": 3}});
it('should error on long strings', () => {
expect(Validators.maxLength(2)(new Control('aaa'))).toEqual({
'maxlength': {'requiredLength': 2, 'actualLength': 3}
});
});
});
describe("pattern", () => {
it("should not error on an empty string",
() => { expect(Validators.pattern("[a-zA-Z ]*")(new Control(""))).toEqual(null); });
describe('pattern', () => {
it('should not error on an empty string',
() => { expect(Validators.pattern('[a-zA-Z ]*')(new Control(''))).toEqual(null); });
it("should not error on null",
() => { expect(Validators.pattern("[a-zA-Z ]*")(new Control(null))).toEqual(null); });
it('should not error on null',
() => { expect(Validators.pattern('[a-zA-Z ]*')(new Control(null))).toEqual(null); });
it("should not error on valid strings",
() => { expect(Validators.pattern("[a-zA-Z ]*")(new Control("aaAA"))).toEqual(null); });
it('should not error on valid strings',
() => { expect(Validators.pattern('[a-zA-Z ]*')(new Control('aaAA'))).toEqual(null); });
it("should error on failure to match string", () => {
expect(Validators.pattern("[a-zA-Z ]*")(new Control("aaa0")))
.toEqual({"pattern": {"requiredPattern": "^[a-zA-Z ]*$", "actualValue": "aaa0"}});
it('should error on failure to match string', () => {
expect(Validators.pattern('[a-zA-Z ]*')(new Control('aaa0'))).toEqual({
'pattern': {'requiredPattern': '^[a-zA-Z ]*$', 'actualValue': 'aaa0'}
});
});
});
describe("compose", () => {
it("should return null when given null",
describe('compose', () => {
it('should return null when given null',
() => { expect(Validators.compose(null)).toBe(null); });
it("should collect errors from all the validators", () => {
var c = Validators.compose([validator("a", true), validator("b", true)]);
expect(c(new Control(""))).toEqual({"a": true, "b": true});
it('should collect errors from all the validators', () => {
var c = Validators.compose([validator('a', true), validator('b', true)]);
expect(c(new Control(''))).toEqual({'a': true, 'b': true});
});
it("should run validators left to right", () => {
var c = Validators.compose([validator("a", 1), validator("a", 2)]);
expect(c(new Control(""))).toEqual({"a": 2});
it('should run validators left to right', () => {
var c = Validators.compose([validator('a', 1), validator('a', 2)]);
expect(c(new Control(''))).toEqual({'a': 2});
});
it("should return null when no errors", () => {
it('should return null when no errors', () => {
var c = Validators.compose([Validators.nullValidator, Validators.nullValidator]);
expect(c(new Control(""))).toEqual(null);
expect(c(new Control(''))).toEqual(null);
});
it("should ignore nulls", () => {
it('should ignore nulls', () => {
var c = Validators.compose([null, Validators.required]);
expect(c(new Control(""))).toEqual({"required": true});
expect(c(new Control(''))).toEqual({'required': true});
});
});
describe("composeAsync", () => {
describe('composeAsync', () => {
function asyncValidator(expected, response) {
return (c) => {
var emitter = new EventEmitter();
@@ -130,43 +121,42 @@ export function main() {
};
}
it("should return null when given null",
it('should return null when given null',
() => { expect(Validators.composeAsync(null)).toEqual(null); });
it("should collect errors from all the validators", fakeAsync(() => {
it('should collect errors from all the validators', fakeAsync(() => {
var c = Validators.composeAsync([
asyncValidator("expected", {"one": true}),
asyncValidator("expected", {"two": true})
asyncValidator('expected', {'one': true}), asyncValidator('expected', {'two': true})
]);
var value = null;
(<Promise<any>>c(new Control("invalid"))).then(v => value = v);
(<Promise<any>>c(new Control('invalid'))).then(v => value = v);
tick(1);
expect(value).toEqual({"one": true, "two": true});
expect(value).toEqual({'one': true, 'two': true});
}));
it("should return null when no errors", fakeAsync(() => {
var c = Validators.composeAsync([asyncValidator("expected", {"one": true})]);
it('should return null when no errors', fakeAsync(() => {
var c = Validators.composeAsync([asyncValidator('expected', {'one': true})]);
var value = null;
(<Promise<any>>c(new Control("expected"))).then(v => value = v);
(<Promise<any>>c(new Control('expected'))).then(v => value = v);
tick(1);
expect(value).toEqual(null);
}));
it("should ignore nulls", fakeAsync(() => {
var c = Validators.composeAsync([asyncValidator("expected", {"one": true}), null]);
it('should ignore nulls', fakeAsync(() => {
var c = Validators.composeAsync([asyncValidator('expected', {'one': true}), null]);
var value = null;
(<Promise<any>>c(new Control("invalid"))).then(v => value = v);
(<Promise<any>>c(new Control('invalid'))).then(v => value = v);
tick(1);
expect(value).toEqual({"one": true});
expect(value).toEqual({'one': true});
}));
});
});
@@ -1,32 +1,15 @@
import {
ddescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach,
AsyncTestCompleter,
inject,
browserDetection
} from 'angular2/testing_internal';
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, AsyncTestCompleter, inject, browserDetection} from 'angular2/testing_internal';
import {SpyChangeDetectorRef} from '../spies';
import {isBlank} from 'angular2/src/facade/lang';
import {AsyncPipe} from 'angular2/common';
import {WrappedValue} from 'angular2/core';
import {
EventEmitter,
ObservableWrapper,
PromiseWrapper,
TimerWrapper
} from 'angular2/src/facade/async';
import {EventEmitter, ObservableWrapper, PromiseWrapper, TimerWrapper} from 'angular2/src/facade/async';
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
import {PromiseCompleter} from 'angular2/src/facade/promise';
export function main() {
describe("AsyncPipe", () => {
describe('AsyncPipe', () => {
describe('Observable', () => {
var emitter;
@@ -40,11 +23,11 @@ export function main() {
pipe = new AsyncPipe(ref);
});
describe("transform", () => {
it("should return null when subscribing to an observable",
describe('transform', () => {
it('should return null when subscribing to an observable',
() => { expect(pipe.transform(emitter)).toBe(null); });
it("should return the latest available value wrapped",
it('should return the latest available value wrapped',
inject([AsyncTestCompleter], (async) => {
pipe.transform(emitter);
@@ -57,7 +40,7 @@ export function main() {
}));
it("should return same value when nothing has changed since the last call",
it('should return same value when nothing has changed since the last call',
inject([AsyncTestCompleter], (async) => {
pipe.transform(emitter);
ObservableWrapper.callEmit(emitter, message);
@@ -69,7 +52,7 @@ export function main() {
}, 0)
}));
it("should dispose of the existing subscription when subscribing to a new observable",
it('should dispose of the existing subscription when subscribing to a new observable',
inject([AsyncTestCompleter], (async) => {
pipe.transform(emitter);
@@ -85,7 +68,7 @@ export function main() {
}, 0)
}));
it("should request a change detection check upon receiving a new value",
it('should request a change detection check upon receiving a new value',
inject([AsyncTestCompleter], (async) => {
pipe.transform(emitter);
ObservableWrapper.callEmit(emitter, message);
@@ -97,11 +80,11 @@ export function main() {
}));
});
describe("ngOnDestroy", () => {
it("should do nothing when no subscription",
describe('ngOnDestroy', () => {
it('should do nothing when no subscription',
() => { expect(() => pipe.ngOnDestroy()).not.toThrow(); });
it("should dispose of the existing subscription", inject([AsyncTestCompleter], (async) => {
it('should dispose of the existing subscription', inject([AsyncTestCompleter], (async) => {
pipe.transform(emitter);
pipe.ngOnDestroy();
@@ -115,7 +98,7 @@ export function main() {
});
});
describe("Promise", () => {
describe('Promise', () => {
var message = new Object();
var pipe: AsyncPipe;
var completer: PromiseCompleter<any>;
@@ -129,11 +112,11 @@ export function main() {
pipe = new AsyncPipe(<any>ref);
});
describe("transform", () => {
it("should return null when subscribing to a promise",
describe('transform', () => {
it('should return null when subscribing to a promise',
() => { expect(pipe.transform(completer.promise)).toBe(null); });
it("should return the latest available value", inject([AsyncTestCompleter], (async) => {
it('should return the latest available value', inject([AsyncTestCompleter], (async) => {
pipe.transform(completer.promise);
completer.resolve(message);
@@ -144,7 +127,7 @@ export function main() {
}, timer)
}));
it("should return unwrapped value when nothing has changed since the last call",
it('should return unwrapped value when nothing has changed since the last call',
inject([AsyncTestCompleter], (async) => {
pipe.transform(completer.promise);
completer.resolve(message);
@@ -156,7 +139,7 @@ export function main() {
}, timer)
}));
it("should dispose of the existing subscription when subscribing to a new promise",
it('should dispose of the existing subscription when subscribing to a new promise',
inject([AsyncTestCompleter], (async) => {
pipe.transform(completer.promise);
@@ -172,7 +155,7 @@ export function main() {
}, timer)
}));
it("should request a change detection check upon receiving a new value",
it('should request a change detection check upon receiving a new value',
inject([AsyncTestCompleter], (async) => {
var markForCheck = ref.spy('markForCheck');
pipe.transform(completer.promise);
@@ -184,22 +167,22 @@ export function main() {
}, timer)
}));
describe("ngOnDestroy", () => {
it("should do nothing when no source",
describe('ngOnDestroy', () => {
it('should do nothing when no source',
() => { expect(() => pipe.ngOnDestroy()).not.toThrow(); });
it("should dispose of the existing source", inject([AsyncTestCompleter], (async) => {
it('should dispose of the existing source', inject([AsyncTestCompleter], (async) => {
pipe.transform(completer.promise);
expect(pipe.transform(completer.promise)).toBe(null);
completer.resolve(message)
TimerWrapper.setTimeout(() => {
expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message));
pipe.ngOnDestroy();
expect(pipe.transform(completer.promise)).toBe(null);
async.done();
}, timer);
TimerWrapper.setTimeout(() => {
expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message));
pipe.ngOnDestroy();
expect(pipe.transform(completer.promise)).toBe(null);
async.done();
}, timer);
}));
});
});
@@ -215,7 +198,7 @@ export function main() {
describe('other types', () => {
it('should throw when given an invalid object', () => {
var pipe = new AsyncPipe(null);
expect(() => pipe.transform(<any>"some bogus object", [])).toThrowError();
expect(() => pipe.transform(<any>'some bogus object', [])).toThrowError();
});
});
});
@@ -1,21 +1,11 @@
import {
ddescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach,
browserDetection
} from 'angular2/testing_internal';
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, browserDetection} from 'angular2/testing_internal';
import {DatePipe} from 'angular2/common';
import {DateWrapper} from 'angular2/src/facade/lang';
import {PipeResolver} from 'angular2/src/core/linker/pipe_resolver';
export function main() {
describe("DatePipe", () => {
describe('DatePipe', () => {
var date;
var pipe;
@@ -27,11 +17,11 @@ export function main() {
it('should be marked as pure',
() => { expect(new PipeResolver().resolve(DatePipe).pure).toEqual(true); });
describe("supports", () => {
it("should support date", () => { expect(pipe.supports(date)).toBe(true); });
it("should support int", () => { expect(pipe.supports(123456789)).toBe(true); });
describe('supports', () => {
it('should support date', () => { expect(pipe.supports(date)).toBe(true); });
it('should support int', () => { expect(pipe.supports(123456789)).toBe(true); });
it("should not support other objects", () => {
it('should not support other objects', () => {
expect(pipe.supports(new Object())).toBe(false);
expect(pipe.supports(null)).toBe(false);
});
@@ -40,7 +30,7 @@ export function main() {
// TODO(mlaval): enable tests when Intl API is no longer used, see
// https://github.com/angular/angular/issues/3333
if (browserDetection.supportsIntlApi) {
describe("transform", () => {
describe('transform', () => {
it('should format each component correctly', () => {
expect(pipe.transform(date, ['y'])).toEqual('2015');
expect(pipe.transform(date, ['yy'])).toEqual('15');
@@ -1,57 +1,51 @@
import {
ddescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach
} from 'angular2/testing_internal';
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/testing_internal';
import {I18nPluralPipe} from 'angular2/common';
import {PipeResolver} from 'angular2/src/core/linker/pipe_resolver';
export function main() {
describe("I18nPluralPipe", () => {
describe('I18nPluralPipe', () => {
var pipe;
var mapping = {'=0': 'No messages.', '=1': 'One message.', 'other': 'There are some messages.'};
var interpolatedMapping =
{'=0': 'No messages.', '=1': 'One message.', 'other': 'There are # messages, that is #.'};
var interpolatedMapping = {
'=0': 'No messages.',
'=1': 'One message.',
'other': 'There are # messages, that is #.'
};
beforeEach(() => { pipe = new I18nPluralPipe(); });
it('should be marked as pure',
() => { expect(new PipeResolver().resolve(I18nPluralPipe).pure).toEqual(true); });
describe("transform", () => {
it("should return 0 text if value is 0", () => {
describe('transform', () => {
it('should return 0 text if value is 0', () => {
var val = pipe.transform(0, [mapping]);
expect(val).toEqual('No messages.');
});
it("should return 1 text if value is 1", () => {
it('should return 1 text if value is 1', () => {
var val = pipe.transform(1, [mapping]);
expect(val).toEqual('One message.');
});
it("should return other text if value is anything other than 0 or 1", () => {
it('should return other text if value is anything other than 0 or 1', () => {
var val = pipe.transform(6, [mapping]);
expect(val).toEqual('There are some messages.');
});
it("should interpolate the value into the text where indicated", () => {
it('should interpolate the value into the text where indicated', () => {
var val = pipe.transform(6, [interpolatedMapping]);
expect(val).toEqual('There are 6 messages, that is 6.');
});
it("should use 'other' if value is undefined", () => {
it('should use \'other\' if value is undefined', () => {
var messageLength;
var val = pipe.transform(messageLength, [interpolatedMapping]);
expect(val).toEqual('There are messages, that is .');
});
it("should not support bad arguments",
it('should not support bad arguments',
() => { expect(() => pipe.transform(0, ['hey'])).toThrowError(); });
});
@@ -1,19 +1,10 @@
import {
ddescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach
} from 'angular2/testing_internal';
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/testing_internal';
import {I18nSelectPipe} from 'angular2/common';
import {PipeResolver} from 'angular2/src/core/linker/pipe_resolver';
export function main() {
describe("I18nSelectPipe", () => {
describe('I18nSelectPipe', () => {
var pipe;
var mapping = {'male': 'Invite him.', 'female': 'Invite her.', 'other': 'Invite them.'};
@@ -22,29 +13,29 @@ export function main() {
it('should be marked as pure',
() => { expect(new PipeResolver().resolve(I18nSelectPipe).pure).toEqual(true); });
describe("transform", () => {
it("should return male text if value is male", () => {
describe('transform', () => {
it('should return male text if value is male', () => {
var val = pipe.transform('male', [mapping]);
expect(val).toEqual('Invite him.');
});
it("should return female text if value is female", () => {
it('should return female text if value is female', () => {
var val = pipe.transform('female', [mapping]);
expect(val).toEqual('Invite her.');
});
it("should return other text if value is anything other than male or female", () => {
it('should return other text if value is anything other than male or female', () => {
var val = pipe.transform('Anything else', [mapping]);
expect(val).toEqual('Invite them.');
});
it("should use 'other' if value is undefined", () => {
it('should use \'other\' if value is undefined', () => {
var gender;
var val = pipe.transform(gender, [mapping]);
expect(val).toEqual('Invite them.');
});
it("should not support bad arguments",
it('should not support bad arguments',
() => { expect(() => pipe.transform('male', ['hey'])).toThrowError(); });
});
@@ -1,24 +1,11 @@
import {
ddescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach,
AsyncTestCompleter,
inject,
proxy,
TestComponentBuilder
} from 'angular2/testing_internal';
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, AsyncTestCompleter, inject, proxy, TestComponentBuilder} from 'angular2/testing_internal';
import {Json, RegExp, NumberWrapper, StringWrapper} from 'angular2/src/facade/lang';
import {Component} from 'angular2/core';
import {JsonPipe} from 'angular2/common';
export function main() {
describe("JsonPipe", () => {
describe('JsonPipe', () => {
var regNewLine = '\n';
var inceptionObj;
var inceptionObjString;
@@ -28,24 +15,29 @@ export function main() {
beforeEach(() => {
inceptionObj = {dream: {dream: {dream: 'Limbo'}}};
inceptionObjString = "{\n" + " \"dream\": {\n" + " \"dream\": {\n" +
" \"dream\": \"Limbo\"\n" + " }\n" + " }\n" + "}";
inceptionObjString = '{\n' +
' "dream": {\n' +
' "dream": {\n' +
' "dream": "Limbo"\n' +
' }\n' +
' }\n' +
'}';
pipe = new JsonPipe();
});
describe("transform", () => {
it("should return JSON-formatted string",
describe('transform', () => {
it('should return JSON-formatted string',
() => { expect(pipe.transform(inceptionObj)).toEqual(inceptionObjString); });
it("should return JSON-formatted string even when normalized", () => {
it('should return JSON-formatted string even when normalized', () => {
var dream1 = normalize(pipe.transform(inceptionObj));
var dream2 = normalize(inceptionObjString);
expect(dream1).toEqual(dream2);
});
it("should return JSON-formatted string similar to Json.stringify", () => {
it('should return JSON-formatted string similar to Json.stringify', () => {
var dream1 = normalize(pipe.transform(inceptionObj));
var dream2 = normalize(Json.stringify(inceptionObj));
expect(dream1).toEqual(dream2);
@@ -59,11 +51,11 @@ export function main() {
let mutable: number[] = [1];
fixture.debugElement.componentInstance.data = mutable;
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText("[\n 1\n]");
expect(fixture.debugElement.nativeElement).toHaveText('[\n 1\n]');
mutable.push(2);
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText("[\n 1,\n 2\n]");
expect(fixture.debugElement.nativeElement).toHaveText('[\n 1,\n 2\n]');
async.done();
});
@@ -1,18 +1,9 @@
import {
ddescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach
} from 'angular2/testing_internal';
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/testing_internal';
import {LowerCasePipe} from 'angular2/common';
export function main() {
describe("LowerCasePipe", () => {
describe('LowerCasePipe', () => {
var upper;
var lower;
var pipe;
@@ -23,20 +14,20 @@ export function main() {
pipe = new LowerCasePipe();
});
describe("transform", () => {
it("should return lowercase", () => {
describe('transform', () => {
it('should return lowercase', () => {
var val = pipe.transform(upper);
expect(val).toEqual(lower);
});
it("should lowercase when there is a new value", () => {
it('should lowercase when there is a new value', () => {
var val = pipe.transform(upper);
expect(val).toEqual(lower);
var val2 = pipe.transform('WAT');
expect(val2).toEqual('wat');
});
it("should not support other objects",
it('should not support other objects',
() => { expect(() => pipe.transform(new Object())).toThrowError(); });
});
@@ -1,14 +1,4 @@
import {
ddescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach,
browserDetection
} from 'angular2/testing_internal';
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, browserDetection} from 'angular2/testing_internal';
import {DecimalPipe, PercentPipe, CurrencyPipe} from 'angular2/common';
@@ -17,12 +7,12 @@ export function main() {
// TODO(mlaval): enable tests when Intl API is no longer used, see
// https://github.com/angular/angular/issues/3333
if (browserDetection.supportsIntlApi) {
describe("DecimalPipe", () => {
describe('DecimalPipe', () => {
var pipe;
beforeEach(() => { pipe = new DecimalPipe(); });
describe("transform", () => {
describe('transform', () => {
it('should return correct value for numbers', () => {
expect(pipe.transform(12345, [])).toEqual('12,345');
expect(pipe.transform(123, ['.2'])).toEqual('123.00');
@@ -33,39 +23,39 @@ export function main() {
expect(pipe.transform(1.1234, [])).toEqual('1.123');
});
it("should not support other objects",
it('should not support other objects',
() => { expect(() => pipe.transform(new Object(), [])).toThrowError(); });
});
});
describe("PercentPipe", () => {
describe('PercentPipe', () => {
var pipe;
beforeEach(() => { pipe = new PercentPipe(); });
describe("transform", () => {
describe('transform', () => {
it('should return correct value for numbers', () => {
expect(pipe.transform(1.23, [])).toEqual('123%');
expect(pipe.transform(1.2, ['.2'])).toEqual('120.00%');
});
it("should not support other objects",
it('should not support other objects',
() => { expect(() => pipe.transform(new Object(), [])).toThrowError(); });
});
});
describe("CurrencyPipe", () => {
describe('CurrencyPipe', () => {
var pipe;
beforeEach(() => { pipe = new CurrencyPipe(); });
describe("transform", () => {
describe('transform', () => {
it('should return correct value for numbers', () => {
expect(pipe.transform(123, [])).toEqual('USD123');
expect(pipe.transform(12, ['EUR', false, '.2'])).toEqual('EUR12.00');
});
it("should not support other objects",
it('should not support other objects',
() => { expect(() => pipe.transform(new Object(), [])).toThrowError(); });
});
});
@@ -1,14 +1,4 @@
import {
ddescribe,
xdescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach
} from 'angular2/testing_internal';
import {ddescribe, xdescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/testing_internal';
import {PipeProvider} from 'angular2/src/core/pipes/pipe_provider';
import {Pipe} from 'angular2/src/core/metadata';
@@ -16,7 +6,7 @@ import {Pipe} from 'angular2/src/core/metadata';
class MyPipe {}
export function main() {
describe("PipeProvider", () => {
describe('PipeProvider', () => {
it('should create a provider out of a type', () => {
var provider = PipeProvider.createFromType(MyPipe, new Pipe({name: 'my-pipe'}));
expect(provider.name).toEqual('my-pipe');
@@ -1,14 +1,4 @@
import {
ddescribe,
xdescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach
} from 'angular2/testing_internal';
import {ddescribe, xdescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/testing_internal';
import {Injector, Inject, provide, Pipe, PipeTransform, OnDestroy} from 'angular2/core';
import {ProtoPipes, Pipes} from 'angular2/src/core/pipes/pipes';
@@ -21,13 +11,13 @@ class PipeA implements PipeTransform, OnDestroy {
class PipeB implements PipeTransform, OnDestroy {
dep;
constructor(@Inject("dep") dep: any) { this.dep = dep; }
constructor(@Inject('dep') dep: any) { this.dep = dep; }
transform(a, b) {}
ngOnDestroy() {}
}
export function main() {
describe("Pipes", () => {
describe('Pipes', () => {
var injector;
beforeEach(() => {
@@ -39,20 +29,20 @@ export function main() {
ProtoPipes.fromProviders([PipeProvider.createFromType(PipeA, new Pipe({name: 'a'}))]);
var pipes = new Pipes(proto, injector);
expect(pipes.get("a").pipe).toBeAnInstanceOf(PipeA);
expect(pipes.get('a').pipe).toBeAnInstanceOf(PipeA);
});
it('should throw when no pipe found', () => {
var proto = ProtoPipes.fromProviders([]);
var pipes = new Pipes(proto, injector);
expect(() => pipes.get("invalid")).toThrowErrorWith("Cannot find pipe 'invalid'");
expect(() => pipes.get('invalid')).toThrowErrorWith('Cannot find pipe \'invalid\'');
});
it('should inject dependencies from the provided injector', () => {
var proto =
ProtoPipes.fromProviders([PipeProvider.createFromType(PipeB, new Pipe({name: 'b'}))]);
var pipes = new Pipes(proto, injector);
expect((<any>pipes.get("b").pipe).dep).toEqual("dependency");
expect((<any>pipes.get('b').pipe).dep).toEqual('dependency');
});
it('should cache pure pipes', () => {
@@ -60,8 +50,8 @@ export function main() {
[PipeProvider.createFromType(PipeA, new Pipe({name: 'a', pure: true}))]);
var pipes = new Pipes(proto, injector);
expect(pipes.get("a").pure).toEqual(true);
expect(pipes.get("a")).toBe(pipes.get("a"));
expect(pipes.get('a').pure).toEqual(true);
expect(pipes.get('a')).toBe(pipes.get('a'));
});
it('should NOT cache impure pipes', () => {
@@ -69,8 +59,8 @@ export function main() {
[PipeProvider.createFromType(PipeA, new Pipe({name: 'a', pure: false}))]);
var pipes = new Pipes(proto, injector);
expect(pipes.get("a").pure).toEqual(false);
expect(pipes.get("a")).not.toBe(pipes.get("a"));
expect(pipes.get('a').pure).toEqual(false);
expect(pipes.get('a')).not.toBe(pipes.get('a'));
});
});
}
@@ -1,23 +1,10 @@
import {
ddescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach,
browserDetection,
inject,
TestComponentBuilder,
AsyncTestCompleter
} from 'angular2/testing_internal';
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, browserDetection, inject, TestComponentBuilder, AsyncTestCompleter} from 'angular2/testing_internal';
import {ReplacePipe} from 'angular2/common';
import {RegExpWrapper, StringJoiner} from 'angular2/src/facade/lang';
export function main() {
describe("ReplacePipe", () => {
describe('ReplacePipe', () => {
var someNumber: number;
var str;
var pipe;
@@ -28,43 +15,43 @@ export function main() {
pipe = new ReplacePipe();
});
describe("transform", () => {
describe('transform', () => {
it("should not support input other than strings and numbers", () => {
expect(() => pipe.transform({}, ["Douglas", "Hugh"])).toThrow();
expect(() => pipe.transform([1, 2, 3], ["Douglas", "Hugh"])).toThrow();
it('should not support input other than strings and numbers', () => {
expect(() => pipe.transform({}, ['Douglas', 'Hugh'])).toThrow();
expect(() => pipe.transform([1, 2, 3], ['Douglas', 'Hugh'])).toThrow();
});
it("should not support patterns other than strings and regular expressions", () => {
expect(() => pipe.transform(str, [{}, "Hugh"])).toThrow();
expect(() => pipe.transform(str, [null, "Hugh"])).toThrow();
expect(() => pipe.transform(str, [123, "Hugh"])).toThrow();
it('should not support patterns other than strings and regular expressions', () => {
expect(() => pipe.transform(str, [{}, 'Hugh'])).toThrow();
expect(() => pipe.transform(str, [null, 'Hugh'])).toThrow();
expect(() => pipe.transform(str, [123, 'Hugh'])).toThrow();
});
it("should not support replacements other than strings and functions", () => {
expect(() => pipe.transform(str, ["Douglas", {}])).toThrow();
expect(() => pipe.transform(str, ["Douglas", null])).toThrow();
expect(() => pipe.transform(str, ["Douglas", 123])).toThrow();
it('should not support replacements other than strings and functions', () => {
expect(() => pipe.transform(str, ['Douglas', {}])).toThrow();
expect(() => pipe.transform(str, ['Douglas', null])).toThrow();
expect(() => pipe.transform(str, ['Douglas', 123])).toThrow();
});
it("should return a new string with the pattern replaced", () => {
var result1 = pipe.transform(str, ["Douglas", "Hugh"]);
it('should return a new string with the pattern replaced', () => {
var result1 = pipe.transform(str, ['Douglas', 'Hugh']);
var result2 = pipe.transform(str, [RegExpWrapper.create("a"), "_"]);
var result2 = pipe.transform(str, [RegExpWrapper.create('a'), '_']);
var result3 = pipe.transform(str, [RegExpWrapper.create("a", "i"), "_"]);
var result3 = pipe.transform(str, [RegExpWrapper.create('a', 'i'), '_']);
var f = (x => { return "Adams!"; });
var f = (x => { return 'Adams!'; });
var result4 = pipe.transform(str, ["Adams", f]);
var result4 = pipe.transform(str, ['Adams', f]);
var result5 = pipe.transform(someNumber, ["2", "4"]);
var result5 = pipe.transform(someNumber, ['2', '4']);
expect(result1).toEqual("Hugh Adams");
expect(result2).toEqual("Dougl_s Ad_ms");
expect(result3).toEqual("Dougl_s _d_ms");
expect(result4).toEqual("Douglas Adams!");
expect(result5).toEqual("44");
expect(result1).toEqual('Hugh Adams');
expect(result2).toEqual('Dougl_s Ad_ms');
expect(result3).toEqual('Dougl_s _d_ms');
expect(result4).toEqual('Douglas Adams!');
expect(result5).toEqual('44');
});
});
@@ -1,23 +1,10 @@
import {
ddescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach,
browserDetection,
inject,
TestComponentBuilder,
AsyncTestCompleter
} from 'angular2/testing_internal';
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, browserDetection, inject, TestComponentBuilder, AsyncTestCompleter} from 'angular2/testing_internal';
import {Component} from 'angular2/core';
import {SlicePipe} from 'angular2/common';
export function main() {
describe("SlicePipe", () => {
describe('SlicePipe', () => {
var list: number[];
var str;
var pipe;
@@ -28,17 +15,17 @@ export function main() {
pipe = new SlicePipe();
});
describe("supports", () => {
it("should support strings", () => { expect(pipe.supports(str)).toBe(true); });
it("should support lists", () => { expect(pipe.supports(list)).toBe(true); });
describe('supports', () => {
it('should support strings', () => { expect(pipe.supports(str)).toBe(true); });
it('should support lists', () => { expect(pipe.supports(list)).toBe(true); });
it("should not support other objects", () => {
it('should not support other objects', () => {
expect(pipe.supports(new Object())).toBe(false);
expect(pipe.supports(null)).toBe(false);
});
});
describe("transform", () => {
describe('transform', () => {
it('should return all items after START index when START is positive and END is omitted',
() => {
@@ -1,18 +1,9 @@
import {
ddescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach
} from 'angular2/testing_internal';
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/testing_internal';
import {UpperCasePipe} from 'angular2/common';
export function main() {
describe("UpperCasePipe", () => {
describe('UpperCasePipe', () => {
var upper;
var lower;
var pipe;
@@ -23,21 +14,21 @@ export function main() {
pipe = new UpperCasePipe();
});
describe("transform", () => {
describe('transform', () => {
it("should return uppercase", () => {
it('should return uppercase', () => {
var val = pipe.transform(lower);
expect(val).toEqual(upper);
});
it("should uppercase when there is a new value", () => {
it('should uppercase when there is a new value', () => {
var val = pipe.transform(lower);
expect(val).toEqual(upper);
var val2 = pipe.transform('wat');
expect(val2).toEqual('WAT');
});
it("should not support other objects",
it('should not support other objects',
() => { expect(() => pipe.transform(new Object())).toThrowError(); });
});