refactor(forms): wrapped all validators into the Validator class
This commit is contained in:
19
modules/angular2/test/forms/form_builder_spec.js
vendored
19
modules/angular2/test/forms/form_builder_spec.js
vendored
@ -1,6 +1,5 @@
|
||||
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, el} from 'angular2/test_lib';
|
||||
import {Control, FormBuilder} from 'angular2/forms';
|
||||
import * as validations from 'angular2/forms';
|
||||
import {Control, FormBuilder, Validators} from 'angular2/forms';
|
||||
|
||||
export function main() {
|
||||
describe("Form Builder", () => {
|
||||
@ -21,21 +20,21 @@ export function main() {
|
||||
it("should create controls from an array", () => {
|
||||
var g = b.group({
|
||||
"login": ["some value"],
|
||||
"password": ["some value", validations.required]
|
||||
"password": ["some value", Validators.required]
|
||||
});
|
||||
|
||||
expect(g.controls["login"].value).toEqual("some value");
|
||||
expect(g.controls["password"].value).toEqual("some value");
|
||||
expect(g.controls["password"].validator).toEqual(validations.required);
|
||||
expect(g.controls["password"].validator).toEqual(Validators.required);
|
||||
});
|
||||
|
||||
it("should use controls", () => {
|
||||
var g = b.group({
|
||||
"login": b.control("some value", validations.required)
|
||||
"login": b.control("some value", Validators.required)
|
||||
});
|
||||
|
||||
expect(g.controls["login"].value).toEqual("some value");
|
||||
expect(g.controls["login"].validator).toBe(validations.required);
|
||||
expect(g.controls["login"].validator).toBe(Validators.required);
|
||||
});
|
||||
|
||||
it("should create groups with optional controls", () => {
|
||||
@ -49,17 +48,17 @@ export function main() {
|
||||
it("should create groups with a custom validator", () => {
|
||||
var g = b.group({
|
||||
"login": "some value"
|
||||
}, {"validator": validations.nullValidator});
|
||||
}, {"validator": Validators.nullValidator});
|
||||
|
||||
expect(g.validator).toBe(validations.nullValidator);
|
||||
expect(g.validator).toBe(Validators.nullValidator);
|
||||
});
|
||||
|
||||
it("should use default validators when no validators are provided", () => {
|
||||
var g = b.group({
|
||||
"login": "some value"
|
||||
});
|
||||
expect(g.controls["login"].validator).toBe(validations.nullValidator);
|
||||
expect(g.validator).toBe(validations.controlGroupValidator);
|
||||
expect(g.controls["login"].validator).toBe(Validators.nullValidator);
|
||||
expect(g.validator).toBe(Validators.group);
|
||||
});
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user