当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript testing.beforeEach函数代码示例

本文整理汇总了TypeScript中@angular/core/testing.beforeEach函数的典型用法代码示例。如果您正苦于以下问题:TypeScript beforeEach函数的具体用法?TypeScript beforeEach怎么用?TypeScript beforeEach使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了beforeEach函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: describe

describe('Component: GenreDetail', () => {
  let builder: TestComponentBuilder;

  beforeEachProviders(() => [GenreDetailComponent]);
  beforeEach(inject([TestComponentBuilder], function (tcb: TestComponentBuilder) {
    builder = tcb;
  }));

  it('should inject the component', inject([GenreDetailComponent],
      (component: GenreDetailComponent) => {
    expect(component).toBeTruthy();
  }));

  it('should create the component', inject([], () => {
    return builder.createAsync(GenreDetailComponentTestController)
      .then((fixture: ComponentFixture<any>) => {
        let query = fixture.debugElement.query(By.directive(GenreDetailComponent));
        expect(query).toBeTruthy();
        expect(query.componentInstance).toBeTruthy();
      });
  }));
});
开发者ID:jernejkavkassw,项目名称:ssw-music-store-module5,代码行数:22,代码来源:genre-detail.component.spec.ts

示例2: describe

describe("WidgetChooserComponent", () => {

	let tcb: TestComponentBuilder;
	let factory: WidgetFactory;
	beforeEachProviders(() => [TestComponentBuilder, {provide: WidgetFactory, useClass: WidgetFactoryMock}]);

	class WidgetFactoryMock {
		createWidget() {
			return new Promise( (resolve, reject) => {
				resolve({instance: { } });
			});
		}
	};

	beforeEach(inject([TestComponentBuilder, WidgetFactory], (_tcb, _factory) => {
		tcb = _tcb;
		factory = _factory;
		spyOn(factory, "createWidget").and.callThrough();
	}));

	it("should create a widget", done => {
		tcb.createAsync(WidgetChooserComponent).then((fixture) => {
			let chooser = fixture.componentInstance;
			chooser.id = "string";
			chooser.settings = { required: true };
			chooser.widget = {id: "string"};
			fixture.detectChanges();
			expect(factory.createWidget).toHaveBeenCalledWith(chooser.container, "string");

			let element = fixture.debugElement.nativeElement.querySelector("input");
			done();
		}).catch(exception => done.fail(exception));

	});

	xit("should put the widget returned by the factory in the DOM", () => { });

});
开发者ID:un33k,项目名称:angular2-schema-form,代码行数:38,代码来源:widgetchooser.component.spec.ts

示例3: describe

describe('Device Grid Configuration Tests', () => {

    beforeAll(() => {
        Object.keys(StorageKeys).forEach(key => {
            StorageKeys[key] += '.test';
        });
    });

    beforeEach(() => {
        // clear out storage
        sessionStorage.clear();
        localStorage.clear();
    });
    
    it('uses default device grid configuration when none present', done => {
        var state = new ConfigurationService();
        state.CurrentDeviceGridView.subscribe(config => {
            expect(config).toEqual(DefaultDeviceGridConfiguration);
            done();
        });
    });
    
    it('uses session storage grid configuration if present', done => {
        var fakeConfig = { name: 'test' };
        sessionStorage.setItem(StorageKeys.CurrentDeviceGridView, JSON.stringify(fakeConfig));
        var state = new ConfigurationService();
        state.CurrentDeviceGridView.subscribe(config => {
            expect(config).toEqual(fakeConfig);
            done();
        });
    });
    
    afterEach(() => {
        // clear out storage
        sessionStorage.clear();
        localStorage.clear();
    });
});
开发者ID:habukira,项目名称:Azure-azure-iot-device-management,代码行数:38,代码来源:configuration.service.spec.ts

示例4: describe

describe('Pipe Ellipsis Tests', () => {
  let ellipsis: EllipsisPipe;

  beforeEach(() => {
    ellipsis = new EllipsisPipe();
  });

  it('Should be keep: "Hello world" when limit: 20', () => {
    expect(ellipsis.transform('Hello world', 20)).toEqual('Hello world');
  });

  it('Should be keep: "Hello world" when limit: 0', () => {
    expect(ellipsis.transform('Hello world', 20)).toEqual('Hello world');
  });

  it('Should be keep: "Hello world" when limit: undefined', () => {
    expect(ellipsis.transform('Hello world', undefined)).toEqual('Hello world');
  });

  it('Should be cut: "Hello w..."', () => {
    expect(ellipsis.transform('Hello world', 7)).toEqual('Hello w...');
  });
});
开发者ID:levinhtin,项目名称:admin,代码行数:23,代码来源:ellipsis.spec.ts

示例5: describe

describe('shared:FormattedTimePipe', () => {
  let formattedTimePipe: FormattedTimePipe;

  beforeEach(() => formattedTimePipe = new FormattedTimePipe());

  // Specs with assertions
  it('should expose a transform() method', () => {
    expect(typeof formattedTimePipe.transform).toEqual('function');
  });

  it('should transform 50 into "0h:50m"', () => {
    expect(formattedTimePipe.transform(50)).toEqual('0h:50m');
  });

  it('should transform 75 into "1h:15m"', () => {
    expect(formattedTimePipe.transform(75)).toEqual('1h:15m');
  });

  it('should transform 100 "1h:40m"', () => {
    expect(formattedTimePipe.transform(100)).toEqual('1h:40m');
  });

});
开发者ID:Jabirfayyaz,项目名称:learning-angular2,代码行数:23,代码来源:formatted-time.pipe.spec.ts

示例6: describe

describe('analytics.framework: Analytics (Base Class)', () => {
  let analyticsService: AnalyticsService;
  let analytics: Analytics;

  beforeEach(() => {
    let injector = ReflectiveInjector.resolveAndCreate([
      ROUTER_FAKE_PROVIDERS,
      // Angulartics2 relies on router for virtual page view tracking
      Angulartics2, Angulartics2Segment, AnalyticsService
    ]);
    analyticsService = injector.get(AnalyticsService);
    analytics = new TestAnalytics(analyticsService);
    analytics.category = 'TEST';
  });

  describe('should allow descendants to track actions', () => {
    it('track', () => {   
      spyOn(analyticsService, 'track');
      analytics.track('action', { category: analytics.category, label: 'Testing' });
      expect(analyticsService.track).toHaveBeenCalledWith('action', { category: analytics.category, label: 'Testing' });
    });
  });
});  
开发者ID:NathanWalker,项目名称:ngTunes,代码行数:23,代码来源:analytics.service.spec.ts

示例7: describe

describe('MyUppercasePipe', () => {
    let pipe: MyUppercasePipe;

    beforeEach(() => {
        pipe = new MyUppercasePipe();
    });

    it('transforms "abc" to "ABC"', () => {
        expect(pipe.transform('abc')).toBe('ABC');
    });

    it('transforms null to ""', () => {
        expect(pipe.transform(null)).toBe('');
    });

    it('transforms undefined to ""', () => {
        expect(pipe.transform(undefined)).toBe('');
    });

    it('transforms "" to ""', () => {
        expect(pipe.transform('')).toBe('');
    });
});
开发者ID:yuyang041060120,项目名称:ng2-webpack,代码行数:23,代码来源:my-uppercase.pipe.spec.ts

示例8: describe

    describe('fill', () => {
      beforeEach(() => { l = [1, 2, 3, 4]; });

      it('should fill the whole list if neither start nor end are specified', () => {
        ListWrapper.fill(l, 9);
        expect(l).toEqual([9, 9, 9, 9]);
      });

      it('should fill up to the end if end is not specified', () => {
        ListWrapper.fill(l, 9, 1);
        expect(l).toEqual([1, 9, 9, 9]);
      });

      it('should support negative start', () => {
        ListWrapper.fill(l, 9, -1);
        expect(l).toEqual([1, 2, 3, 9]);
      });

      it('should support negative end', () => {
        ListWrapper.fill(l, 9, -2, -1);
        expect(l).toEqual([1, 2, 9, 4]);
      });
    });
开发者ID:0xJoKe,项目名称:angular,代码行数:23,代码来源:collection_spec.ts

示例9: describe

describe('AppService', () => {

  beforeEach(() => addProviders([
    Title,
    AppService
  ]));

  it('setTitle() works', inject([AppService], (appService: AppService) => {
    let newTitle = '';
    appService.setTitle(newTitle);
    expect(appService.getTitle()).toEqual(`${appService.baseTitle}`);
    newTitle = 'abc';
    appService.setTitle(newTitle);
    expect(appService.getTitle()).toEqual(`${newTitle}${appService.titleSeparator}${appService.baseTitle}`);
  }));

  it('inferTitleFromUrl() works', inject([AppService], (appService: AppService) => {
    const newTitle = 'Question Add';
    appService.inferTitleFromUrl('question/add');
    expect(appService.getTitle()).toEqual(`${newTitle}${appService.titleSeparator}${appService.baseTitle}`);
  }));

});
开发者ID:DavyDuDu,项目名称:angular2-minimalist-starter,代码行数:23,代码来源:app.service.spec.ts

示例10: describe

describe('Component: LunchMenu', () => {
  let builder: TestComponentBuilder;

  beforeEachProviders(() => [LunchMenuComponent]);
  beforeEach(inject([TestComponentBuilder], function (tcb: TestComponentBuilder) {
    builder = tcb;
  }));

  it('should inject the component', inject([LunchMenuComponent],
      (component: LunchMenuComponent) => {
    expect(component).toBeTruthy();
  }));

  // todo check why it's missing, might be related to commented module.id in typings file that was generated by angular-cli.
  // it('should create the component', inject([], () => {
  //   return builder.createAsync(LunchMenuComponentTestController)
  //     .then((fixture: ComponentFixture<any>) => {
  //       let query = fixture.debugElement.query(By.directive(LunchMenuComponent));
  //       expect(query).toBeTruthy();
  //       expect(query.componentInstance).toBeTruthy();
  //     });
  // }));
});
开发者ID:jvanderbiest,项目名称:lunchorder,代码行数:23,代码来源:lunch-menu.component.spec.ts


注:本文中的@angular/core/testing.beforeEach函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。