0
I am trying to perform a unit test for a method made in typescript, this is the method:
createTasksForms(): void {
this.task.forEach(task => {
task.form = this.form.group({ name: ['', [Validators.required, Validators.pattern(/^[^ ]/)]] });
task.form.controls.name.valueChanges.subscribe(value => { value; });
task.canEdit = false;
});
}
I was able to test it until the subscribe (code coverage), but it does not enter the (value => { value; }), my test is like this for now:
it('should create tasks forms', async () => {
component.task = task;
await component.createTasksForms();
component.task = { form: {controls: { name: { valueChanges: { } } } } };
expect(component.task).toBeDefined();
});
Come some solution?
That’s very strange your code, Component. task should be an array to be traversed by for each task element, each task element has a form property like Formgroup. That your subscribe code now does nothing. What the point of it??
– Eduardo Vargas
its function createTasksForms returns nothing pq vc put a await in it?
– Eduardo Vargas
a tip would be to use map instead of foreach, in javascript and functional programming in general mutation is something very bad
– Eduardo Vargas
I noticed, I was reviewing my code and it doesn’t really make sense this part of it, I think it was something after we readapted some functions. Vlw :D
– accelerate