Skip to content

Commit 3525c9c

Browse files
committed
chore(forms): moved tests/forms to typescript
1 parent 05774f6 commit 3525c9c

File tree

6 files changed

+644
-675
lines changed

6 files changed

+644
-675
lines changed

modules/angular2/test/forms/directives_spec.js renamed to modules/angular2/test/forms/directives_spec.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1-
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, el,
2-
AsyncTestCompleter, inject} from 'angular2/test_lib';
1+
import {
2+
ddescribe,
3+
describe,
4+
it,
5+
iit,
6+
xit,
7+
expect,
8+
beforeEach,
9+
afterEach,
10+
el,
11+
AsyncTestCompleter,
12+
inject
13+
} from 'angular2/test_lib';
314
import {ControlGroup, ControlDirective, ControlGroupDirective} from 'angular2/forms';
415

516
export function main() {
617
describe("Form Directives", () => {
718
describe("Control", () => {
819
it("should throw when the group is not found and the control is not set", () => {
920
var c = new ControlDirective(null);
10-
expect(() => {
11-
c.controlOrName = 'login';
12-
}).toThrowError(new RegExp('No control group found for "login"'));
21+
expect(() => { c.controlOrName = 'login'; })
22+
.toThrowError(new RegExp('No control group found for "login"'));
1323
});
1424

1525
it("should throw when cannot find the control in the group", () => {
1626
var emptyGroup = new ControlGroupDirective(null);
1727
emptyGroup.controlOrName = new ControlGroup({});
1828

1929
var c = new ControlDirective(emptyGroup);
20-
expect(() => {
21-
c.controlOrName = 'login';
22-
}).toThrowError(new RegExp('Cannot find control "login"'));
30+
expect(() => { c.controlOrName = 'login'; })
31+
.toThrowError(new RegExp('Cannot find control "login"'));
2332
});
2433
});
2534
});
Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,66 @@
1-
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, el} from 'angular2/test_lib';
1+
import {
2+
ddescribe,
3+
describe,
4+
it,
5+
iit,
6+
xit,
7+
expect,
8+
beforeEach,
9+
afterEach,
10+
el
11+
} from 'angular2/test_lib';
212
import {Control, FormBuilder, Validators} from 'angular2/forms';
313

414
export function main() {
515
describe("Form Builder", () => {
616
var b;
717

8-
beforeEach(() => {
9-
b = new FormBuilder();
10-
});
18+
beforeEach(() => { b = new FormBuilder(); });
1119

1220
it("should create controls from a value", () => {
13-
var g = b.group({
14-
"login": "some value"
15-
});
21+
var g = b.group({"login": "some value"});
1622

1723
expect(g.controls["login"].value).toEqual("some value");
1824
});
1925

2026
it("should create controls from an array", () => {
21-
var g = b.group({
22-
"login": ["some value"],
23-
"password": ["some value", Validators.required]
24-
});
27+
var g = b.group({"login": ["some value"], "password": ["some value", Validators.required]});
2528

2629
expect(g.controls["login"].value).toEqual("some value");
2730
expect(g.controls["password"].value).toEqual("some value");
2831
expect(g.controls["password"].validator).toEqual(Validators.required);
2932
});
3033

3134
it("should use controls", () => {
32-
var g = b.group({
33-
"login": b.control("some value", Validators.required)
34-
});
35+
var g = b.group({"login": b.control("some value", Validators.required)});
3536

3637
expect(g.controls["login"].value).toEqual("some value");
3738
expect(g.controls["login"].validator).toBe(Validators.required);
3839
});
3940

4041
it("should create groups with optional controls", () => {
41-
var g = b.group({
42-
"login": "some value"
43-
}, {"optionals": {"login" : false}});
42+
var g = b.group({"login": "some value"}, {"optionals": {"login": false}});
4443

4544
expect(g.contains("login")).toEqual(false);
4645
});
4746

4847
it("should create groups with a custom validator", () => {
49-
var g = b.group({
50-
"login": "some value"
51-
}, {"validator": Validators.nullValidator});
48+
var g = b.group({"login": "some value"}, {"validator": Validators.nullValidator});
5249

5350
expect(g.validator).toBe(Validators.nullValidator);
5451
});
5552

5653
it("should use default validators when no validators are provided", () => {
57-
var g = b.group({
58-
"login": "some value"
59-
});
54+
var g = b.group({"login": "some value"});
6055
expect(g.controls["login"].validator).toBe(Validators.nullValidator);
6156
expect(g.validator).toBe(Validators.group);
6257
});
6358

6459
it("should create control arrays", () => {
6560
var c = b.control("three");
66-
var a = b.array([
67-
"one",
68-
["two", Validators.required],
69-
c,
70-
b.array(['four'])
71-
]);
61+
var a = b.array(["one", ["two", Validators.required], c, b.array(['four'])]);
7262

7363
expect(a.value).toEqual(['one', 'two', 'three', ['four']]);
7464
});
7565
});
7666
}
77-

0 commit comments

Comments
 (0)