Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(forms): Added missing selfOnly tests #12317

Merged
merged 1 commit into from Oct 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions modules/@angular/forms/test/form_array_spec.ts
Expand Up @@ -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`));
Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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']);

Expand Down
6 changes: 6 additions & 0 deletions modules/@angular/forms/test/form_control_spec.ts
Expand Up @@ -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');
Expand Down
22 changes: 21 additions & 1 deletion modules/@angular/forms/test/form_group_spec.ts
Expand Up @@ -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'
Expand Down Expand Up @@ -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': ''});
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -541,7 +562,6 @@ export function main() {
g.reset({'one': {value: '', disabled: true}});
expect(logger).toEqual(['control1', 'control2', 'group', 'form']);
});

});

});
Expand Down