本文整理汇总了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();
});
}));
});
示例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", () => { });
});
示例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();
});
});
示例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...');
});
});
示例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');
});
});
示例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' });
});
});
});
示例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('');
});
});
示例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]);
});
});
示例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}`);
}));
});
示例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();
// });
// }));
});