I'm building a loginform component with the following interface:
<login-form onlogin="submit()"></login-form>
And that's the testing code:
it("Should send credentials out of the component", async(() => {
TestBed.compileComponents().then(() => {
const fixture = TestBed.createComponent(LoginFormComponent);
let component = fixture.componentInstance;
spyOn(component.onlogin, "emit");
let domRef = fixture.nativeElement;
domRef.querySelector("input[name='username']").value = "test@test.com";
domRef.querySelector("input[name='password']").value = '1234';
domRef.querySelector("form").dispatchEvent(new Event('submit'));
fixture.detectChanges();
let expectedSubmitData:UserCredentials = {
username: "test@test.com",
password: "1234"
};
expect(component.onlogin.emit).toHaveBeenCalledWith(expectedSubmitData);
});
}));
I'm getting this message:
Expected spy emit to have been called with [ Object({ username: 'test@test.com', password: '1234' }) ] but actual calls were [ Object({ username: '', password: '' }) ]
So, what's the way to fill input values and the model detects those changes?