Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class FormComponent {
- @Input() office: Office;
- @Input() officeLoading: boolean;
- ...
- }
- <form *ngIf="!officeLoading" (ngSubmit)="saveForm(form)" #form="ngForm" novalidate>
- <mat-form-field>
- <input
- class="company-name"
- matInput
- placeholder="Company Name"
- type="text"
- name="companyName"
- required
- #companyName="ngModel"
- [ngModel]="office?.companyName">
- <mat-error *ngIf="companyName.errors?.required && companyName.dirty">
- Company name is required
- </mat-error>
- </mat-form-field>
- ...
- </form>
- describe('FormComponent', () => {
- let component: FormComponent;
- let fixture: ComponentFixture<FormComponent>;
- let el: DebugElement;
- beforeEach(async(() => {
- TestBed.configureTestingModule({
- imports: [
- BrowserAnimationsModule,
- FormsModule,
- MatInputModule,
- OverlayModule,
- StoreModule.forRoot({}),
- ],
- declarations: [FormComponent],
- providers: [Actions, MatSnackBar, Store],
- }).compileComponents();
- }));
- beforeEach(() => {
- fixture = TestBed.createComponent(FormComponent);
- component = fixture.componentInstance;
- el = fixture.debugElement;
- component.office = null;
- component.officeLoading = false;
- fixture.detectChanges();
- });
- it('should fill out form based on what comes back from API', () => {
- expect(component.office).toBe(null);
- expect(el.query(By.css('input.company-name')).nativeElement.value).toBe('');
- component.office = {
- companyName: 'Test Name',
- };
- component.officeLoading = false;
- fixture.detectChanges();
- expect(el.query(By.css('input.company-name')).nativeElement.value).toBe(
- 'Test Name',
- );
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement