I'm writing a test that each INPUT field should be not-empty. Either I don't know how to write this test (likely) or Jasmine can't handle multiple actions in a single it().
Here is something like what I tried to write:
it('fails to login for blank credential fields', async(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
comp = fixture.componentInstance;
de = fixture.debugElement;
let elLoginButton = de.query(By.css('#login'));
comp.name = '';
comp.password = 'filled';
elLoginButton.triggerEventHandler('click', null);
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(comp.name).toEqual('', 'name of (blank, filled) test');
expect(comp.password).toEqual('filled', 'password of (blank, filled) test');
});
comp.name = 'filled';
comp.password = '';
elLoginButton.triggerEventHandler('click', null);
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(comp.name).toEqual('filled', 'name of (filled, blank) test');
expect(comp.password).toEqual('', 'password of (filled, blank) test');
});
});
}));
I intend that the (filled, blank) test be executed and its expect() actions evaluated, then the (blank, filled) test be completed.
What I'm seeing in the debugger is that the background process for "click" is done for the (filled, blank) test is run. Then the background process for (blank, filled) is run. Then all of the expects() are run. This means that the (filled, blank) versions of expect() see a "comp" from the (blank, filled) test.
In the end, I created two different it() tests. Is there a better way than "two separate tests" for this?