On Friday, March 9, 2018 at 1:45:20 AM UTC+5:30, louis745 wrote: > > > Hello everyone, > > I try to unit test this validator and I wonder to to give a value to the > AbstractControl. Thanks for your precious help. > > My validator > > export class VerifierNombresValidator { > > static plage(min: number, max: number): ValidatorFn { > return (c: AbstractControl): { [key: string]: boolean } | null => > { > > if ((c.value) && c.value >= min && c.value <= max) { > return null; > } > return { 'plage': true }; > }; > } > } > > My unit test (but not working) : > > > it('plage pour la valeur 3', () => { > let validatorFn = VerifierNombresValidator.apply(88); > let control = { value: '6' } > > VerifierNombresValidator.arguments(control as AbstractControl); > let result = VerifierNombresValidator.plage(1,5); > > expect(result['plage']).toBeUndefined(); > }); >
solution: Just pass the AbstractControl param as inner function it('plage pour la valeur 3', () => { let control = { value: '6' } let result = VerifierNombresValidator.plage(1,5)(control as AbstractControl); expect(result['plage']).toBeUndefined(); }); -- You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group. To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/angular/405977df-f2d6-4174-adcd-e5e9ef7fa43f%40googlegroups.com.