test(forms): added missing selfOnly tests (#12317)
This commit is contained in:
parent
a5419608e0
commit
15fc5dd7ee
@ -123,6 +123,13 @@ export function main() {
|
|||||||
expect(form.value).toEqual({'parent': ['one', 'two']});
|
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)', () => {
|
it('should throw if fields are missing from supplied value (subset)', () => {
|
||||||
expect(() => a.setValue([, 'two']))
|
expect(() => a.setValue([, 'two']))
|
||||||
.toThrowError(new RegExp(`Must supply a value for form control at index: 0`));
|
.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']});
|
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)', () => {
|
it('should ignore fields that are missing from supplied value (subset)', () => {
|
||||||
a.patchValue([, 'two']);
|
a.patchValue([, 'two']);
|
||||||
expect(a.value).toEqual(['', 'two']);
|
expect(a.value).toEqual(['', 'two']);
|
||||||
@ -291,6 +305,13 @@ export function main() {
|
|||||||
expect(a.value).toEqual(['initial value', '']);
|
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', () => {
|
it('should set its own value if boxed value passed', () => {
|
||||||
a.setValue(['new value', 'new value']);
|
a.setValue(['new value', 'new value']);
|
||||||
|
|
||||||
|
@ -429,6 +429,12 @@ export function main() {
|
|||||||
expect(c.value).toBe('initial value');
|
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', () => {
|
it('should reset to a specific value if passed with boxed value', () => {
|
||||||
c.setValue('new value');
|
c.setValue('new value');
|
||||||
expect(c.value).toBe('new value');
|
expect(c.value).toBe('new value');
|
||||||
|
@ -185,6 +185,13 @@ export function main() {
|
|||||||
expect(form.value).toEqual({'parent': {'one': 'one', 'two': 'two'}});
|
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)', () => {
|
it('should throw if fields are missing from supplied value (subset)', () => {
|
||||||
expect(() => g.setValue({
|
expect(() => g.setValue({
|
||||||
'one': 'one'
|
'one': 'one'
|
||||||
@ -283,6 +290,13 @@ export function main() {
|
|||||||
expect(form.value).toEqual({'parent': {'one': 'one', 'two': 'two'}});
|
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)', () => {
|
it('should ignore fields that are missing from supplied value (subset)', () => {
|
||||||
g.patchValue({'one': 'one'});
|
g.patchValue({'one': 'one'});
|
||||||
expect(g.value).toEqual({'one': 'one', 'two': ''});
|
expect(g.value).toEqual({'one': 'one', 'two': ''});
|
||||||
@ -401,6 +415,13 @@ export function main() {
|
|||||||
expect(form.value).toEqual({'g': {'one': null, 'two': null}});
|
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', () => {
|
it('should mark itself as pristine', () => {
|
||||||
g.markAsDirty();
|
g.markAsDirty();
|
||||||
expect(g.pristine).toBe(false);
|
expect(g.pristine).toBe(false);
|
||||||
@ -541,7 +562,6 @@ export function main() {
|
|||||||
g.reset({'one': {value: '', disabled: true}});
|
g.reset({'one': {value: '', disabled: true}});
|
||||||
expect(logger).toEqual(['control1', 'control2', 'group', 'form']);
|
expect(logger).toEqual(['control1', 'control2', 'group', 'form']);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user