本文整理汇总了TypeScript中@angular/testing.beforeEach函数的典型用法代码示例。如果您正苦于以下问题:TypeScript beforeEach函数的具体用法?TypeScript beforeEach怎么用?TypeScript beforeEach使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了beforeEach函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('SumPipe', () => {
let pipe: SumPipe;
beforeEach(() => {
pipe = new SumPipe();
});
it('Should return 10', () => {
expect(pipe.transform([1,2,3,4])).toEqual(10);
});
it('Should return 1', () => {
expect(pipe.transform([1])).toEqual(1);
});
it('Should return 2', () => {
expect(pipe.transform([1,1])).toEqual(2);
});
it('Should return 15', () => {
expect(pipe.transform(15)).toEqual(15);
});
});
示例2: describe
describe('RepeatPipe', () => {
let pipe: RepeatPipe;
beforeEach(() => {
pipe = new RepeatPipe();
});
it('Should do nothing', () => {
expect(pipe.transform('a', 1, '')).toEqual('a');
});
it('Should repeat two times', () => {
expect(pipe.transform('a', 2, '')).toEqual('aa');
});
it('Should repeat two times with space', () => {
expect(pipe.transform('a', 2, ' ')).toEqual('a a');
});
it('Should return the value unchanged', () => {
expect(pipe.transform(1, null)).toEqual(1);
});
});
示例3: describe
describe('CountPipe', () => {
let pipe: CountPipe;
beforeEach(() => {
pipe = new CountPipe();
});
it('Should return the length of the collection', () => {
expect(pipe.transform([1,2])).toEqual(2);
});
it('Should return the length of the object (keys)', () => {
expect(pipe.transform({ a: 1, b: 2, c: 3})).toEqual(3);
});
it('Should return the value unchanged', () => {
expect(pipe.transform('a')).toEqual('a');
});
});
示例4: describe
describe('CeilPipe', () => {
let pipe: CeilPipe;
beforeEach(() => {
pipe = new CeilPipe();
});
it('Should return 4', () => {
expect(pipe.transform(3.4, 0)).toEqual(4);
});
it('Should return 1', () => {
expect(pipe.transform(1, 0)).toEqual(1);
});
it('Should return 1', () => {
expect(pipe.transform(0.65, 0)).toEqual(1);
});
it('Should return 1.5', () => {
expect(pipe.transform(1.5, 1)).toEqual(1.5);
});
it('Should return 1.55', () => {
expect(pipe.transform(1.5444, 2)).toEqual(1.55);
});
});
示例5: describe
describe('Login Component', () => {
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
let tcb: TestComponentBuilder;
beforeEachProviders(() => [
TestComponentBuilder,
provide(DirectiveResolver, {useClass: MockDirectiveResolver}),
provide(ViewResolver, {useClass: MockViewResolver}),
LoginComponent,
]);
beforeEach(inject([TestComponentBuilder], (tcb_) => {
tcb = tcb_;
}));
it('should render form', (done) => {
tcb.createAsync(LoginComponent)
.then((fixture) => {
let element = fixture.nativeElement;
fixture.detectChanges();
let form = element.querySelector('form');
expect(form).toBeTruthy();
expect(form.querySelector('input[name="username"]')).toBeTruthy();
expect(form.querySelector('input[name="password"]')).toBeTruthy();
done();
});
});
});
示例6: describe
describe('TakePipe', () => {
let pipe: TakePipe;
beforeEach(() => {
pipe = new TakePipe();
});
it('Should return []', () => {
expect(pipe.transform([])).toEqual([]);
});
it('Should return [1]', () => {
const value = [1, 2, 3, 4];
expect(pipe.transform(value)).toEqual([1]);
expect(value).toEqual([1, 2, 3, 4]); // Check integrity
});
it ('Should return [1, 2]', () => {
expect(pipe.transform([1, 2, 3, 4], 2)).toEqual([1, 2]);
});
it('Should return the value unchanged', () => {
expect(pipe.transform('a')).toEqual('a');
});
})
示例7: describe
describe('ToArrayPipe', () => {
let pipe: ToArrayPipe;
beforeEach(() => {
pipe = new ToArrayPipe();
});
const value = {
a: 1,
b: 2,
c: 3
};
it ('should transform the object to an array', () => {
expect(pipe.transform(value)).toEqual([1, 2, 3]);
});
it ('should return the input unchanged', () => {
expect(pipe.transform('a')).toEqual('a');
});
});
示例8: describe
describe('TemplatePipe', () => {
let pipe: TemplatePipe;
beforeEach(() => {
pipe = new TemplatePipe();
});
it ('Should replace the parameters', () => {
expect(pipe.transform('Hello $1', 'World')).toEqual('Hello World');
});
it ('Should replace the parameters #2', () => {
expect(pipe.transform('Hello $1, how is it $2', 'World', 'going?')).toEqual('Hello World, how is it going?');
});
it('Should return the value unchanged', () => {
expect(pipe.transform(1, [null])).toEqual(1);
});
});
示例9: describe
describe('MapPipe', () => {
let pipe: MapPipe;
beforeEach(() => {
pipe = new MapPipe();
});
it('Should return the modified array', () => {
const array = [0, 1, 2, 3];
const fn = function (item) {
return ++item;
};
expect(pipe.transform(array, fn)).toEqual([1, 2, 3, 4]);
expect(array).toEqual([0, 1, 2, 3]); // Check integrity
});
it('Should return the original array', () => {
// undefined to avoid typescript error
expect(pipe.transform([1,2], undefined)).toEqual([1, 2]);
});
it('Should return the value unchanged', () => {
expect(pipe.transform('a', null)).toEqual('a');
});
})
示例10: describe
describe('Dashboard Component', () => {
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
let tcb: TestComponentBuilder;
beforeEachProviders(() => [
TestComponentBuilder,
HTTP_PROVIDERS,
ROUTER_FAKE_PROVIDERS,
provide(Location, {useClass: SpyLocation}),
provide(DirectiveResolver, {useClass: MockDirectiveResolver}),
provide(ViewResolver, {useClass: MockViewResolver}),
HeroService,
AppComponent,
]);
beforeEach(inject([TestComponentBuilder], (tcb_) => {
tcb = tcb_;
}));
it('should render the title', (done) => {
return tcb.createAsync(DashboardComponent)
.then(fixture => {
let component = fixture.componentInstance;
component.title = 'Top_heroes';
fixture.detectChanges();
let element = fixture.nativeElement;
expect(element.querySelector('h3').innerText).toContain('Top_heroes');
done();
});
});
});