Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. export class FormComponent {
  2. @Input() office: Office;
  3. @Input() officeLoading: boolean;
  4.  
  5. ...
  6. }
  7.  
  8. <form *ngIf="!officeLoading" (ngSubmit)="saveForm(form)" #form="ngForm" novalidate>
  9. <mat-form-field>
  10. <input
  11. class="company-name"
  12. matInput
  13. placeholder="Company Name"
  14. type="text"
  15. name="companyName"
  16. required
  17. #companyName="ngModel"
  18. [ngModel]="office?.companyName">
  19. <mat-error *ngIf="companyName.errors?.required && companyName.dirty">
  20. Company name is required
  21. </mat-error>
  22. </mat-form-field>
  23. ...
  24. </form>
  25.  
  26. describe('FormComponent', () => {
  27. let component: FormComponent;
  28. let fixture: ComponentFixture<FormComponent>;
  29. let el: DebugElement;
  30.  
  31. beforeEach(async(() => {
  32. TestBed.configureTestingModule({
  33. imports: [
  34. BrowserAnimationsModule,
  35. FormsModule,
  36. MatInputModule,
  37. OverlayModule,
  38. StoreModule.forRoot({}),
  39. ],
  40. declarations: [FormComponent],
  41. providers: [Actions, MatSnackBar, Store],
  42. }).compileComponents();
  43. }));
  44.  
  45. beforeEach(() => {
  46. fixture = TestBed.createComponent(FormComponent);
  47. component = fixture.componentInstance;
  48. el = fixture.debugElement;
  49. component.office = null;
  50. component.officeLoading = false;
  51. fixture.detectChanges();
  52. });
  53.  
  54. it('should fill out form based on what comes back from API', () => {
  55. expect(component.office).toBe(null);
  56. expect(el.query(By.css('input.company-name')).nativeElement.value).toBe('');
  57. component.office = {
  58. companyName: 'Test Name',
  59. };
  60. component.officeLoading = false;
  61. fixture.detectChanges();
  62.  
  63. expect(el.query(By.css('input.company-name')).nativeElement.value).toBe(
  64. 'Test Name',
  65. );
  66. });
  67. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement