当前位置: 首页>>代码示例>>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;未经允许,请勿转载。