fix(forms): update value and validity when controls are added

Closes #8826
This commit is contained in:
Kara Erickson
2016-06-08 14:06:20 -07:00
parent 29c2dcff61
commit 50acb96130
4 changed files with 44 additions and 7 deletions

View File

@ -351,6 +351,33 @@ export function main() {
});
});
describe("adding and removing controls", () => {
it("should update value and validity when control is added", () => {
var g = new ControlGroup({ "one": new Control("1") });
expect(g.value).toEqual({"one": "1"});
expect(g.valid).toBe(true);
g.addControl("two", new Control("2", Validators.minLength(10)));
expect(g.value).toEqual({"one": "1","two": "2"});
expect(g.valid).toBe(false);
});
it("should update value and validity when control is removed", () => {
var g = new ControlGroup({
"one": new Control("1"),
"two": new Control("2", Validators.minLength(10))
});
expect(g.value).toEqual({"one": "1", "two": "2"});
expect(g.valid).toBe(false);
g.removeControl("two");
expect(g.value).toEqual({"one": "1"});
expect(g.valid).toBe(true);
});
});
describe("errors", () => {
it("should run the validator when the value changes", () => {
var simpleValidator = (c) =>