當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript app.component.AppComponent類代碼示例

本文整理匯總了TypeScript中@integration/app.component.AppComponent的典型用法代碼示例。如果您正苦於以下問題:TypeScript component.AppComponent類的具體用法?TypeScript component.AppComponent怎麽用?TypeScript component.AppComponent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了component.AppComponent類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: describe

describe('AppComponent', () => {
  let fixture: ComponentFixture<AppComponent>;
  let component: AppComponent;

  const initialState = {
    todos: {
      todo: [],
      pizza: { model: undefined }
    }
  };

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [AppModule, RouterTestingModule, FormsModule, ReactiveFormsModule],
      providers: [{ provide: ComponentFixtureAutoDetect, useValue: true }]
    });

    fixture = TestBed.createComponent(AppComponent);
    component = fixture.componentInstance;

    // reset store because of storage plugin
    const store = TestBed.get(Store);
    store.reset(initialState);
  });

  it('should add a todo', () => {
    component.addTodo('Get Milk');
    component.addTodo('Clean Bathroom');

    component.todos$.subscribe((state: Todo[]) => {
      expect(state.length).toBe(2);
    });
  });

  it('should remove a todo', () => {
    component.addTodo('Get Milk');
    component.addTodo('Clean Bathroom');
    component.removeTodo(1);

    component.todos$.subscribe((state: Todo[]) => {
      expect(state.length).toBe(1);
      expect(state[0]).toBe('Get Milk');
    });
  });

  it('should set toppings using form control', fakeAsync(() => {
    component.pizzaForm.patchValue({ toppings: 'oli' });
    tick(200);
    let flag = false;

    component.pizza$.pipe(take(1)).subscribe((pizza: Pizza) => {
      flag = true;
      expect(pizza.model.toppings).toBe('oli');
      expect(pizza.model.crust).toBe('thin');
    });

    expect(flag).toBe(true);

    component.pizzaForm.patchValue({ toppings: 'olives', crust: 'thick' });
    tick(200);
    flag = false;

    component.pizza$.pipe(take(1)).subscribe((pizza: Pizza) => {
      flag = true;
      expect(pizza.model.toppings).toBe('olives');
      expect(pizza.model.crust).toBe('thick');
    });

    expect(flag).toBe(true);
  }));

  it('should set toppings prefix', fakeAsync(() => {
    component.pizzaForm.patchValue({ toppings: 'cheese' });
    tick(200);
    component.onPrefix();
    let flag = false;
    tick(200);

    component.pizza$.pipe(take(1)).subscribe((pizza: Pizza) => {
      flag = true;
      expect(pizza.model).toBeDefined();
      expect(pizza.model.toppings).toBe('Mr. cheese');
      expect(pizza.model.crust).toBe('thin');
    });

    expect(flag).toBe(true);
    discardPeriodicTasks();
  }));

  it('should load data in pizza form', () => {
    component.onLoadData();
    let flag = false;

    component.pizza$.pipe(take(1)).subscribe((pizza: Pizza) => {
      flag = true;
      expect(pizza.model.toppings).toBe('pineapple');
      expect(pizza.model.crust).toBe('medium');
      expect(pizza.model.extras).toEqual([false, false, true]);
    });

//.........這裏部分代碼省略.........
開發者ID:LucasFrecia,項目名稱:store,代碼行數:101,代碼來源:app.component.spec.ts

示例2: it

  it('should add a todo', () => {
    component.addTodo('Get Milk');
    component.addTodo('Clean Bathroom');

    component.todos$.subscribe((state: Todo[]) => {
      expect(state.length).toBe(2);
    });
  });
開發者ID:LucasFrecia,項目名稱:store,代碼行數:8,代碼來源:app.component.spec.ts


注:本文中的@integration/app.component.AppComponent類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。