test(forms): added missing selfOnly tests (#12317)

This commit is contained in:
Florian Kinder
2016-10-18 07:51:13 +02:00
committed by Igor Minar
parent a5419608e0
commit 15fc5dd7ee
3 changed files with 48 additions and 1 deletions

View File

@ -123,6 +123,13 @@ export function main() {
expect(form.value).toEqual({'parent': ['one', 'two']});
});
it('should not update the parent explicitly specified', () => {
const form = new FormGroup({'parent': a});
a.setValue(['one', 'two'], {onlySelf: true});
expect(form.value).toEqual({parent: ['', '']});
});
it('should throw if fields are missing from supplied value (subset)', () => {
expect(() => a.setValue([, 'two']))
.toThrowError(new RegExp(`Must supply a value for form control at index: 0`));
@ -219,6 +226,13 @@ export function main() {
expect(form.value).toEqual({'parent': ['one', 'two']});
});
it('should not update the parent explicitly specified', () => {
const form = new FormGroup({'parent': a});
a.patchValue(['one', 'two'], {onlySelf: true});
expect(form.value).toEqual({parent: ['', '']});
});
it('should ignore fields that are missing from supplied value (subset)', () => {
a.patchValue([, 'two']);
expect(a.value).toEqual(['', 'two']);
@ -291,6 +305,13 @@ export function main() {
expect(a.value).toEqual(['initial value', '']);
});
it('should not update the parent when explicitly specified', () => {
const form = new FormGroup({'a': a});
a.reset(['one', 'two'], {onlySelf: true});
expect(form.value).toEqual({a: ['initial value', '']});
});
it('should set its own value if boxed value passed', () => {
a.setValue(['new value', 'new value']);