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']);

View File

@ -429,6 +429,12 @@ export function main() {
expect(c.value).toBe('initial value');
});
it('should not set the parent when explicitly specified', () => {
const g = new FormGroup({'one': c});
c.patchValue('newValue', {onlySelf: true});
expect(g.value).toEqual({'one': 'initial value'});
});
it('should reset to a specific value if passed with boxed value', () => {
c.setValue('new value');
expect(c.value).toBe('new value');

View File

@ -185,6 +185,13 @@ export function main() {
expect(form.value).toEqual({'parent': {'one': 'one', 'two': 'two'}});
});
it('should not update the parent when explicitly specified', () => {
const form = new FormGroup({'parent': g});
g.setValue({'one': 'one', 'two': 'two'}, {onlySelf: true});
expect(form.value).toEqual({parent: {'one': '', 'two': ''}});
});
it('should throw if fields are missing from supplied value (subset)', () => {
expect(() => g.setValue({
'one': 'one'
@ -283,6 +290,13 @@ export function main() {
expect(form.value).toEqual({'parent': {'one': 'one', 'two': 'two'}});
});
it('should not update the parent when explicitly specified', () => {
const form = new FormGroup({'parent': g});
g.patchValue({'one': 'one', 'two': 'two'}, {onlySelf: true});
expect(form.value).toEqual({parent: {'one': '', 'two': ''}});
});
it('should ignore fields that are missing from supplied value (subset)', () => {
g.patchValue({'one': 'one'});
expect(g.value).toEqual({'one': 'one', 'two': ''});
@ -401,6 +415,13 @@ export function main() {
expect(form.value).toEqual({'g': {'one': null, 'two': null}});
});
it('should not update the parent when explicitly specified', () => {
const form = new FormGroup({'g': g});
g.reset({'one': 'new value', 'two': 'new value'}, {onlySelf: true});
expect(form.value).toEqual({g: {'one': 'initial value', 'two': ''}});
});
it('should mark itself as pristine', () => {
g.markAsDirty();
expect(g.pristine).toBe(false);
@ -541,7 +562,6 @@ export function main() {
g.reset({'one': {value: '', disabled: true}});
expect(logger).toEqual(['control1', 'control2', 'group', 'form']);
});
});
});