Click here to Skip to main content
15,887,368 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi , I am following the unit test cases from the below article.

https://code.tutsplus.com/tutorials/testing-components-in-angular-using-jasmine--cms-29165 (part 1 and part2)

The problem is, dom value settings from spec files by inspecting the element and checking with model values doesn't seem to be working when using material element.

What I have tried:

I have checked many sites but none showing how to do when using material.

I have tried below things but it is working for input elemnt but not for select and many other material elemnts

it('should accept input values', () => {
            // Query the input selectors
            question1 = fixture.debugElement.query(By.css('mat-select')).nativeElement;
            answer1 = fixture.debugElement.query(By.css('input[type=text]')).nativeElement;

            // Set the input element's value to mockPaste
            question1.value = mockSecurityModel.question1.toString();
            answer1.value = mockSecurityModel.answer1;

            // Dispatch an event to tell the component input value has changed
            question1.dispatchEvent(new Event('change'));
            answer1.dispatchEvent(new Event('input'));

            // expect(mockSecurityModel.question1).toEqual(component.viewModel.question1);
            expect(mockSecurityModel.answer1).toEqual(component.viewModel.answer1);

        });


and now here the problem is I unable to validate my test case for mat-select.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900