Example #1
0
 ngOnInit() {
   this.validator = equalTo(this.equalTo);
 }
Example #2
0
 it('should not set the parent when explicitly specified', () => {
   c.patchValue('newValue', {onlySelf: true});
   expect(g.value).toEqual({'one': 'oldValue'});
 });
Example #3
0
    describe('reset()', () => {
      let c: FormControl;

      beforeEach(() => { c = new FormControl('initial value'); });

      it('should reset to a specific value if passed', () => {
        c.setValue('new value');
        expect(c.value).toBe('new value');

        c.reset('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', () => {
        c.setValue('new value');
        expect(c.value).toBe('new value');

        c.reset({value: 'initial value', disabled: false});
        expect(c.value).toBe('initial value');
      });

      it('should clear the control value if no value is passed', () => {
        c.setValue('new value');
        expect(c.value).toBe('new value');

        c.reset();
        expect(c.value).toBe(null);
      });

      it('should update the value of any parent controls with passed value', () => {
        const g = new FormGroup({'one': c});
        c.setValue('new value');
        expect(g.value).toEqual({'one': 'new value'});

        c.reset('initial value');
        expect(g.value).toEqual({'one': 'initial value'});
      });

      it('should update the value of any parent controls with null value', () => {
        const g = new FormGroup({'one': c});
        c.setValue('new value');
        expect(g.value).toEqual({'one': 'new value'});

        c.reset();
        expect(g.value).toEqual({'one': null});
      });

      it('should mark the control as pristine', () => {
        c.markAsDirty();
        expect(c.pristine).toBe(false);

        c.reset();
        expect(c.pristine).toBe(true);
      });

      it('should set the parent pristine state if all pristine', () => {
        const g = new FormGroup({'one': c});
        c.markAsDirty();
        expect(g.pristine).toBe(false);

        c.reset();
        expect(g.pristine).toBe(true);
      });

      it('should not set the parent pristine state if it has other dirty controls', () => {
        const c2 = new FormControl('two');
        const g = new FormGroup({'one': c, 'two': c2});
        c.markAsDirty();
        c2.markAsDirty();

        c.reset();
        expect(g.pristine).toBe(false);
      });

      it('should mark the control as untouched', () => {
        c.markAsTouched();
        expect(c.untouched).toBe(false);

        c.reset();
        expect(c.untouched).toBe(true);
      });

      it('should set the parent untouched state if all untouched', () => {
        const g = new FormGroup({'one': c});
        c.markAsTouched();
        expect(g.untouched).toBe(false);

        c.reset();
        expect(g.untouched).toBe(true);
      });

      it('should not set the parent untouched state if other touched controls', () => {
        const c2 = new FormControl('two');
        const g = new FormGroup({'one': c, 'two': c2});
        c.markAsTouched();
        c2.markAsTouched();

        c.reset();
        expect(g.untouched).toBe(false);
      });

      it('should retain the disabled state of the control', () => {
        c.disable();
        c.reset();

        expect(c.disabled).toBe(true);
      });

      it('should set disabled state based on boxed value if passed', () => {
        c.disable();
        c.reset({value: null, disabled: false});

        expect(c.disabled).toBe(false);
      });

      describe('reset() events', () => {
        let g: FormGroup, c2: FormControl, logger: any[];

        beforeEach(() => {
          c2 = new FormControl('two');
          g = new FormGroup({'one': c, 'two': c2});
          logger = [];
        });

        it('should emit one valueChange event per reset control', () => {
          g.valueChanges.subscribe(() => logger.push('group'));
          c.valueChanges.subscribe(() => logger.push('control1'));
          c2.valueChanges.subscribe(() => logger.push('control2'));

          c.reset();
          expect(logger).toEqual(['control1', 'group']);
        });

        it('should not fire an event when explicitly specified', fakeAsync(() => {
             g.valueChanges.subscribe((value) => { throw 'Should not happen'; });
             c.valueChanges.subscribe((value) => { throw 'Should not happen'; });
             c2.valueChanges.subscribe((value) => { throw 'Should not happen'; });

             c.reset(null, {emitEvent: false});

             tick();
           }));

        it('should emit one statusChange event per reset control', () => {
          g.statusChanges.subscribe(() => logger.push('group'));
          c.statusChanges.subscribe(() => logger.push('control1'));
          c2.statusChanges.subscribe(() => logger.push('control2'));

          c.reset();
          expect(logger).toEqual(['control1', 'group']);
        });

        it('should emit one statusChange event per disabled control', () => {
          g.statusChanges.subscribe(() => logger.push('group'));
          c.statusChanges.subscribe(() => logger.push('control1'));
          c2.statusChanges.subscribe(() => logger.push('control2'));

          c.reset({value: null, disabled: true});
          expect(logger).toEqual(['control1', 'group']);
        });
      });

    });
Example #4
0
      it('should not fire an event when explicitly specified', fakeAsync(() => {
           c.valueChanges.subscribe((value) => { throw 'Should not happen'; });

           c.setValue('newValue', {emitEvent: false});
           tick();
         }));
Example #5
0
 it('should set the value of the control', () => {
   c.patchValue('newValue');
   expect(c.value).toEqual('newValue');
 });
Example #6
0
 it('should rerun the validator when the value changes', () => {
   const c = new FormControl('value', Validators.required);
   c.setValue(null);
   expect(c.valid).toEqual(false);
 });
Example #7
0
 it('should be true after changing the value of the control', () => {
   const c = new FormControl('value');
   c.markAsDirty();
   expect(c.dirty).toEqual(true);
 });
Example #8
0
 it('should unset error when values are equal', () => {
   y.setErrors({ match: true });
   CdValidators.match('x', 'y')(form);
   formHelper.expectValid('x');
   formHelper.expectValid('y');
 });
Example #9
0
 it('should keep other existing errors', () => {
   y.setErrors({ match: true, notUnique: true });
   CdValidators.match('x', 'y')(form);
   formHelper.expectValid('x');
   formHelper.expectError('y', 'notUnique');
 });
	ngAfterViewInit(): void {
		this.control.updateValueAndValidity(this.value || undefined);

		super.ngAfterViewInit();
	}
	ngOnChanges(changes: IInputChanges): void {
		if (changes.value) {
			this.control.setValue(changes.value.currentValue);
		}
	}
Example #12
0
    describe('valueChanges & statusChanges', () => {
      let c: FormControl;

      beforeEach(() => { c = new FormControl('old', Validators.required); });

      it('should fire an event after the value has been updated',
         inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
           c.valueChanges.subscribe({
             next: (value: any) => {
               expect(c.value).toEqual('new');
               expect(value).toEqual('new');
               async.done();
             }
           });
           c.setValue('new');
         }));

      it('should fire an event after the status has been updated to invalid', fakeAsync(() => {
           c.statusChanges.subscribe({
             next: (status: any) => {
               expect(c.status).toEqual('INVALID');
               expect(status).toEqual('INVALID');
             }
           });

           c.setValue('');
           tick();
         }));

      it('should fire an event after the status has been updated to pending', fakeAsync(() => {
           const c = new FormControl('old', Validators.required, asyncValidator('expected'));

           const log: any[] /** TODO #9100 */ = [];
           c.valueChanges.subscribe({next: (value: any) => log.push(`value: '${value}'`)});

           c.statusChanges.subscribe({next: (status: any) => log.push(`status: '${status}'`)});

           c.setValue('');
           tick();

           c.setValue('nonEmpty');
           tick();

           c.setValue('expected');
           tick();

           expect(log).toEqual([
             '' +
                 'value: \'\'',
             'status: \'INVALID\'',
             'value: \'nonEmpty\'',
             'status: \'PENDING\'',
             'status: \'INVALID\'',
             'value: \'expected\'',
             'status: \'PENDING\'',
             'status: \'VALID\'',
           ]);
         }));

      // TODO: remove the if statement after making observable delivery sync
      it('should update set errors and status before emitting an event',
         inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
           c.valueChanges.subscribe((value: any /** TODO #9100 */) => {
             expect(c.valid).toEqual(false);
             expect(c.errors).toEqual({'required': true});
             async.done();
           });
           c.setValue('');
         }));

      it('should return a cold observable',
         inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
           c.setValue('will be ignored');
           c.valueChanges.subscribe({
             next: (value: any) => {
               expect(value).toEqual('new');
               async.done();
             }
           });
           c.setValue('new');
         }));
    });
Example #13
0
      it('should set disabled state based on boxed value if passed', () => {
        c.disable();
        c.reset({value: null, disabled: false});

        expect(c.disabled).toBe(false);
      });
Example #14
0
      it('should retain the disabled state of the control', () => {
        c.disable();
        c.reset();

        expect(c.disabled).toBe(true);
      });
Example #15
0
    describe('setValue', () => {
      let c: FormControl, c2: FormControl, a: FormArray;

      beforeEach(() => {
        c = new FormControl('');
        c2 = new FormControl('');
        a = new FormArray([c, c2]);
      });

      it('should set its own value', () => {
        a.setValue(['one', 'two']);
        expect(a.value).toEqual(['one', 'two']);
      });

      it('should set child values', () => {
        a.setValue(['one', 'two']);
        expect(c.value).toEqual('one');
        expect(c2.value).toEqual('two');
      });

      it('should set values for disabled child controls', () => {
        c2.disable();
        a.setValue(['one', 'two']);
        expect(c2.value).toEqual('two');
        expect(a.value).toEqual(['one']);
        expect(a.getRawValue()).toEqual(['one', 'two']);
      });

      it('should set value for disabled arrays', () => {
        a.disable();
        a.setValue(['one', 'two']);
        expect(c.value).toEqual('one');
        expect(c2.value).toEqual('two');
        expect(a.value).toEqual(['one', 'two']);
      });

      it('should set parent values', () => {
        const form = new FormGroup({'parent': a});
        a.setValue(['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)', () => {
        expect(() => a.setValue([, 'two']))
            .toThrowError(new RegExp(`Must supply a value for form control at index: 0`));
      });

      it('should throw if a value is provided for a missing control (superset)', () => {
        expect(() => a.setValue([
          'one', 'two', 'three'
        ])).toThrowError(new RegExp(`Cannot find form control at index 2`));
      });

      it('should throw if a value is not provided for a disabled control', () => {
        c2.disable();
        expect(() => a.setValue(['one']))
            .toThrowError(new RegExp(`Must supply a value for form control at index: 1`));
      });

      it('should throw if no controls are set yet', () => {
        const empty = new FormArray([]);
        expect(() => empty.setValue(['one']))
            .toThrowError(new RegExp(`no form controls registered with this array`));
      });

      describe('setValue() events', () => {
        let form: FormGroup;
        let logger: any[];

        beforeEach(() => {
          form = new FormGroup({'parent': a});
          logger = [];
        });

        it('should emit one valueChange event per control', () => {
          form.valueChanges.subscribe(() => logger.push('form'));
          a.valueChanges.subscribe(() => logger.push('array'));
          c.valueChanges.subscribe(() => logger.push('control1'));
          c2.valueChanges.subscribe(() => logger.push('control2'));

          a.setValue(['one', 'two']);
          expect(logger).toEqual(['control1', 'control2', 'array', 'form']);
        });

        it('should not fire an event when explicitly specified', fakeAsync(() => {
             form.valueChanges.subscribe((value) => { throw 'Should not happen'; });
             a.valueChanges.subscribe((value) => { throw 'Should not happen'; });
             c.valueChanges.subscribe((value) => { throw 'Should not happen'; });
             c2.valueChanges.subscribe((value) => { throw 'Should not happen'; });

             a.setValue(['one', 'two'], {emitEvent: false});
             tick();
           }));

        it('should emit one statusChange event per control', () => {
          form.statusChanges.subscribe(() => logger.push('form'));
          a.statusChanges.subscribe(() => logger.push('array'));
          c.statusChanges.subscribe(() => logger.push('control1'));
          c2.statusChanges.subscribe(() => logger.push('control2'));

          a.setValue(['one', 'two']);
          expect(logger).toEqual(['control1', 'control2', 'array', 'form']);
        });
      });
    });
Example #16
0
 it('should throw if a value is not provided for a disabled control', () => {
   c2.disable();
   expect(() => a.setValue(['one']))
       .toThrowError(new RegExp(`Must supply a value for form control at index: 1`));
 });
 onRadioChange(val, formControl: FormControl) {
   formControl.patchValue(val);
 }
Example #18
0
    describe('patchValue', () => {
      let c: FormControl, c2: FormControl, a: FormArray;

      beforeEach(() => {
        c = new FormControl('');
        c2 = new FormControl('');
        a = new FormArray([c, c2]);
      });

      it('should set its own value', () => {
        a.patchValue(['one', 'two']);
        expect(a.value).toEqual(['one', 'two']);
      });

      it('should set child values', () => {
        a.patchValue(['one', 'two']);
        expect(c.value).toEqual('one');
        expect(c2.value).toEqual('two');
      });

      it('should patch disabled control values', () => {
        c2.disable();
        a.patchValue(['one', 'two']);
        expect(c2.value).toEqual('two');
        expect(a.value).toEqual(['one']);
        expect(a.getRawValue()).toEqual(['one', 'two']);
      });

      it('should patch disabled control arrays', () => {
        a.disable();
        a.patchValue(['one', 'two']);
        expect(c.value).toEqual('one');
        expect(c2.value).toEqual('two');
        expect(a.value).toEqual(['one', 'two']);
      });

      it('should set parent values', () => {
        const form = new FormGroup({'parent': a});
        a.patchValue(['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)', () => {
        a.patchValue([, 'two']);
        expect(a.value).toEqual(['', 'two']);
      });

      it('should not ignore fields that are null', () => {
        a.patchValue([null]);
        expect(a.value).toEqual([null, '']);
      });

      it('should ignore any value provided for a missing control (superset)', () => {
        a.patchValue([, , 'three']);
        expect(a.value).toEqual(['', '']);
      });

      describe('patchValue() events', () => {
        let form: FormGroup;
        let logger: any[];

        beforeEach(() => {
          form = new FormGroup({'parent': a});
          logger = [];
        });

        it('should emit one valueChange event per control', () => {
          form.valueChanges.subscribe(() => logger.push('form'));
          a.valueChanges.subscribe(() => logger.push('array'));
          c.valueChanges.subscribe(() => logger.push('control1'));
          c2.valueChanges.subscribe(() => logger.push('control2'));

          a.patchValue(['one', 'two']);
          expect(logger).toEqual(['control1', 'control2', 'array', 'form']);
        });

        it('should not emit valueChange events for skipped controls', () => {
          form.valueChanges.subscribe(() => logger.push('form'));
          a.valueChanges.subscribe(() => logger.push('array'));
          c.valueChanges.subscribe(() => logger.push('control1'));
          c2.valueChanges.subscribe(() => logger.push('control2'));

          a.patchValue(['one']);
          expect(logger).toEqual(['control1', 'array', 'form']);
        });

        it('should not fire an event when explicitly specified', fakeAsync(() => {
             form.valueChanges.subscribe((value) => { throw 'Should not happen'; });
             a.valueChanges.subscribe((value) => { throw 'Should not happen'; });
             c.valueChanges.subscribe((value) => { throw 'Should not happen'; });
             c2.valueChanges.subscribe((value) => { throw 'Should not happen'; });

             a.patchValue(['one', 'two'], {emitEvent: false});
             tick();
           }));

        it('should emit one statusChange event per control', () => {
          form.statusChanges.subscribe(() => logger.push('form'));
          a.statusChanges.subscribe(() => logger.push('array'));
          c.statusChanges.subscribe(() => logger.push('control1'));
          c2.statusChanges.subscribe(() => logger.push('control2'));

          a.patchValue(['one', 'two']);
          expect(logger).toEqual(['control1', 'control2', 'array', 'form']);
        });
      });
    });
Example #19
0
 fakeAsync(() => {
   const c = new FormControl('value', [asyncValidator('expected')]);
   c.disable();
   tick();
   expect(c.status).toEqual('DISABLED');
 }));
Example #20
0
    describe('reset()', () => {
      let c: FormControl, c2: FormControl, a: FormArray;

      beforeEach(() => {
        c = new FormControl('initial value');
        c2 = new FormControl('');
        a = new FormArray([c, c2]);
      });

      it('should set its own value if value passed', () => {
        a.setValue(['new value', 'new value']);

        a.reset(['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', () => {
        a.setValue(['new value', 'new value']);

        a.reset([{value: 'initial value', disabled: false}, '']);
        expect(a.value).toEqual(['initial value', '']);
      });

      it('should clear its own value if no value passed', () => {
        a.setValue(['new value', 'new value']);

        a.reset();
        expect(a.value).toEqual([null, null]);
      });

      it('should set the value of each of its child controls if value passed', () => {
        a.setValue(['new value', 'new value']);

        a.reset(['initial value', '']);
        expect(c.value).toBe('initial value');
        expect(c2.value).toBe('');
      });

      it('should clear the value of each of its child controls if no value', () => {
        a.setValue(['new value', 'new value']);

        a.reset();
        expect(c.value).toBe(null);
        expect(c2.value).toBe(null);
      });

      it('should set the value of its parent if value passed', () => {
        const form = new FormGroup({'a': a});
        a.setValue(['new value', 'new value']);

        a.reset(['initial value', '']);
        expect(form.value).toEqual({'a': ['initial value', '']});
      });

      it('should clear the value of its parent if no value passed', () => {
        const form = new FormGroup({'a': a});
        a.setValue(['new value', 'new value']);

        a.reset();
        expect(form.value).toEqual({'a': [null, null]});
      });

      it('should mark itself as pristine', () => {
        a.markAsDirty();
        expect(a.pristine).toBe(false);

        a.reset();
        expect(a.pristine).toBe(true);
      });

      it('should mark all child controls as pristine', () => {
        c.markAsDirty();
        c2.markAsDirty();
        expect(c.pristine).toBe(false);
        expect(c2.pristine).toBe(false);

        a.reset();
        expect(c.pristine).toBe(true);
        expect(c2.pristine).toBe(true);
      });

      it('should mark the parent as pristine if all siblings pristine', () => {
        const c3 = new FormControl('');
        const form = new FormGroup({'a': a, 'c3': c3});

        a.markAsDirty();
        expect(form.pristine).toBe(false);

        a.reset();
        expect(form.pristine).toBe(true);
      });

      it('should not mark the parent pristine if any dirty siblings', () => {
        const c3 = new FormControl('');
        const form = new FormGroup({'a': a, 'c3': c3});

        a.markAsDirty();
        c3.markAsDirty();
        expect(form.pristine).toBe(false);

        a.reset();
        expect(form.pristine).toBe(false);
      });

      it('should mark itself as untouched', () => {
        a.markAsTouched();
        expect(a.untouched).toBe(false);

        a.reset();
        expect(a.untouched).toBe(true);
      });

      it('should mark all child controls as untouched', () => {
        c.markAsTouched();
        c2.markAsTouched();
        expect(c.untouched).toBe(false);
        expect(c2.untouched).toBe(false);

        a.reset();
        expect(c.untouched).toBe(true);
        expect(c2.untouched).toBe(true);
      });

      it('should mark the parent untouched if all siblings untouched', () => {
        const c3 = new FormControl('');
        const form = new FormGroup({'a': a, 'c3': c3});

        a.markAsTouched();
        expect(form.untouched).toBe(false);

        a.reset();
        expect(form.untouched).toBe(true);
      });

      it('should not mark the parent untouched if any touched siblings', () => {
        const c3 = new FormControl('');
        const form = new FormGroup({'a': a, 'c3': c3});

        a.markAsTouched();
        c3.markAsTouched();
        expect(form.untouched).toBe(false);

        a.reset();
        expect(form.untouched).toBe(false);
      });

      it('should retain previous disabled state', () => {
        a.disable();
        a.reset();

        expect(a.disabled).toBe(true);
      });

      it('should set child disabled state if boxed value passed', () => {
        a.disable();
        a.reset([{value: '', disabled: false}, '']);

        expect(c.disabled).toBe(false);
        expect(a.disabled).toBe(false);
      });


      describe('reset() events', () => {
        let form: FormGroup, c3: FormControl, logger: any[];

        beforeEach(() => {
          c3 = new FormControl('');
          form = new FormGroup({'a': a, 'c3': c3});
          logger = [];
        });

        it('should emit one valueChange event per reset control', () => {
          form.valueChanges.subscribe(() => logger.push('form'));
          a.valueChanges.subscribe(() => logger.push('array'));
          c.valueChanges.subscribe(() => logger.push('control1'));
          c2.valueChanges.subscribe(() => logger.push('control2'));
          c3.valueChanges.subscribe(() => logger.push('control3'));

          a.reset();
          expect(logger).toEqual(['control1', 'control2', 'array', 'form']);
        });

        it('should not fire an event when explicitly specified', fakeAsync(() => {
             form.valueChanges.subscribe((value) => { throw 'Should not happen'; });
             a.valueChanges.subscribe((value) => { throw 'Should not happen'; });
             c.valueChanges.subscribe((value) => { throw 'Should not happen'; });
             c2.valueChanges.subscribe((value) => { throw 'Should not happen'; });
             c3.valueChanges.subscribe((value) => { throw 'Should not happen'; });

             a.reset([], {emitEvent: false});
             tick();
           }));

        it('should emit one statusChange event per reset control', () => {
          form.statusChanges.subscribe(() => logger.push('form'));
          a.statusChanges.subscribe(() => logger.push('array'));
          c.statusChanges.subscribe(() => logger.push('control1'));
          c2.statusChanges.subscribe(() => logger.push('control2'));
          c3.statusChanges.subscribe(() => logger.push('control3'));

          a.reset();
          expect(logger).toEqual(['control1', 'control2', 'array', 'form']);
        });
      });
    });
Example #21
0
 it('should be true after markAsTouched runs', () => {
   const c = new FormControl('value');
   c.markAsTouched();
   expect(c.touched).toEqual(true);
 });
Example #22
0
      it('should be true after changing the value of the control', () => {
        c.markAsDirty();

        expect(a.dirty).toEqual(true);
      });
Example #23
0
    describe('patchValue', () => {
      let g: FormGroup, c: FormControl;
      beforeEach(() => {
        c = new FormControl('oldValue');
        g = new FormGroup({'one': c});
      });

      it('should set the value of the control', () => {
        c.patchValue('newValue');
        expect(c.value).toEqual('newValue');
      });

      it('should invoke ngOnChanges if it is present', () => {
        let ngOnChanges: any;
        c.registerOnChange((v: any) => ngOnChanges = ['invoked', v]);

        c.patchValue('newValue');

        expect(ngOnChanges).toEqual(['invoked', 'newValue']);
      });

      it('should not invoke on change when explicitly specified', () => {
        let onChange: any = null;
        c.registerOnChange((v: any) => onChange = ['invoked', v]);

        c.patchValue('newValue', {emitModelToViewChange: false});

        expect(onChange).toBeNull();
      });

      it('should set the parent', () => {
        c.patchValue('newValue');
        expect(g.value).toEqual({'one': 'newValue'});
      });

      it('should not set the parent when explicitly specified', () => {
        c.patchValue('newValue', {onlySelf: true});
        expect(g.value).toEqual({'one': 'oldValue'});
      });

      it('should fire an event', fakeAsync(() => {
           c.valueChanges.subscribe((value) => { expect(value).toEqual('newValue'); });

           c.patchValue('newValue');
           tick();
         }));

      it('should not fire an event when explicitly specified', fakeAsync(() => {
           c.valueChanges.subscribe((value) => { throw 'Should not happen'; });

           c.patchValue('newValue', {emitEvent: false});

           tick();
         }));

      it('should patch value on a disabled control', () => {
        g.addControl('two', new FormControl('two'));
        c.disable();

        c.patchValue('new value');
        expect(c.value).toEqual('new value');
        expect(g.value).toEqual({'two': 'two'});
      });
    });
Example #24
0
      it('should be true after child control is marked as touched', () => {
        c.markAsTouched();

        expect(a.touched).toEqual(true);
      });
Example #25
0
 it('should set the parent', () => {
   c.patchValue('newValue');
   expect(g.value).toEqual({'one': 'newValue'});
 });
Example #26
0
      it('should be true after changing the value of the control', () => {
        c.markAsPending();

        expect(c.pending).toEqual(true);
        expect(a.pending).toEqual(true);
      });
Example #27
0
      it('should fire an event', fakeAsync(() => {
           c.valueChanges.subscribe((value) => { expect(value).toEqual('newValue'); });

           c.patchValue('newValue');
           tick();
         }));
Example #28
0
      it('should not update the parent when onlySelf = true', () => {
        c.markAsPending({onlySelf: true});

        expect(c.pending).toEqual(true);
        expect(a.pending).toEqual(false);
      });
Example #29
0
 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'});
 });
Example #30
0
 it('should not error when values are equal', () => {
   CdValidators.match('x', 'y')(form);
   expect(x.hasError('match')).toBeFalsy();
   expect(y.hasError('match')).toBeFalsy();
 });