本文整理汇总了TypeScript中@angular/core/testing.inject函数的典型用法代码示例。如果您正苦于以下问题:TypeScript inject函数的具体用法?TypeScript inject怎么用?TypeScript inject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了inject函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('Basic usage', () => {
let scroll: ScrollDispatcher;
let fixture: ComponentFixture<ScrollingComponent>;
beforeEach(inject([ScrollDispatcher], (s: ScrollDispatcher) => {
scroll = s;
fixture = TestBed.createComponent(ScrollingComponent);
fixture.detectChanges();
}));
it('should be registered with the scrollable directive with the scroll service', () => {
const componentScrollable = fixture.componentInstance.scrollable;
expect(scroll.scrollContainers.has(componentScrollable)).toBe(true);
});
it('should have the scrollable directive deregistered when the component is destroyed', () => {
const componentScrollable = fixture.componentInstance.scrollable;
expect(scroll.scrollContainers.has(componentScrollable)).toBe(true);
fixture.destroy();
expect(scroll.scrollContainers.has(componentScrollable)).toBe(false);
});
it('should notify through the directive and service that a scroll event occurred',
fakeAsync(() => {
// Listen for notifications from scroll directive
const scrollable = fixture.componentInstance.scrollable;
const directiveSpy = jasmine.createSpy('directive scroll callback');
scrollable.elementScrolled().subscribe(directiveSpy);
// Listen for notifications from scroll service with a throttle of 100ms
const throttleTime = 100;
const serviceSpy = jasmine.createSpy('service scroll callback');
scroll.scrolled(throttleTime).subscribe(serviceSpy);
// Emit a scroll event from the scrolling element in our component.
// This event should be picked up by the scrollable directive and notify.
// The notification should be picked up by the service.
dispatchFakeEvent(fixture.componentInstance.scrollingElement.nativeElement, 'scroll', false);
// The scrollable directive should have notified the service immediately.
expect(directiveSpy).toHaveBeenCalled();
// Verify that the throttle is used, the service should wait for the throttle time until
// sending the notification.
expect(serviceSpy).not.toHaveBeenCalled();
// After the throttle time, the notification should be sent.
tick(throttleTime);
expect(serviceSpy).toHaveBeenCalled();
}));
it('should not execute the global events in the Angular zone', () => {
scroll.scrolled(0).subscribe(() => {});
dispatchFakeEvent(document, 'scroll', false);
expect(fixture.ngZone!.isStable).toBe(true);
});
it('should not execute the scrollable events in the Angular zone', () => {
dispatchFakeEvent(fixture.componentInstance.scrollingElement.nativeElement, 'scroll');
expect(fixture.ngZone!.isStable).toBe(true);
});
it('should be able to unsubscribe from the global scrollable', () => {
const spy = jasmine.createSpy('global scroll callback');
const subscription = scroll.scrolled(0).subscribe(spy);
dispatchFakeEvent(document, 'scroll', false);
expect(spy).toHaveBeenCalledTimes(1);
subscription.unsubscribe();
dispatchFakeEvent(document, 'scroll', false);
expect(spy).toHaveBeenCalledTimes(1);
});
it('should complete the `scrolled` stream on destroy', () => {
const completeSpy = jasmine.createSpy('complete spy');
const subscription = scroll.scrolled(0).subscribe(undefined, undefined, completeSpy);
scroll.ngOnDestroy();
expect(completeSpy).toHaveBeenCalled();
subscription.unsubscribe();
});
});
开发者ID:clydin,项目名称:material2,代码行数:89,代码来源:scroll-dispatcher.spec.ts
示例2: describe
describe('with default BreakPoints', () => {
let knownBreakPoints: BreakPoint[] = [];
let findMediaQuery: (alias: string) => string = (alias) => {
const NOT_FOUND = `${alias} not found`;
return knownBreakPoints.reduce((mediaQuery: string | null, bp) => {
return mediaQuery || ((bp.alias === alias) ? bp.mediaQuery : null);
}, null) as string || NOT_FOUND;
};
beforeEach(() => {
// Configure testbed to prepare services
TestBed.configureTestingModule({
providers: [MockMatchMediaProvider, ObservableMediaProvider]
});
});
beforeEach(inject([BREAKPOINTS], (breakpoints: BreakPoint[]) => {
// Cache reference to list for easy testing...
knownBreakPoints = breakpoints;
}));
it('can supports the `.isActive()` API', async(inject(
[ObservableMedia, MatchMedia],
(media, matchMedia) => {
expect(media).toBeDefined();
// Activate mediaQuery associated with 'md' alias
matchMedia.activate('md');
expect(media.isActive('md')).toBeTruthy();
matchMedia.activate('lg');
expect(media.isActive('lg')).toBeTruthy();
expect(media.isActive('md')).toBeFalsy();
})));
it('can supports RxJS operators', inject(
[ObservableMedia, MatchMedia],
(mediaService, matchMedia) => {
let count = 0,
subscription = mediaService.asObservable().pipe(
filter((change: MediaChange) => change.mqAlias == 'md'),
map((change: MediaChange) => change.mqAlias)
).subscribe(_ => {
count += 1;
});
// Activate mediaQuery associated with 'md' alias
matchMedia.activate('sm');
expect(count).toEqual(0);
matchMedia.activate('md');
expect(count).toEqual(1);
matchMedia.activate('lg');
expect(count).toEqual(1);
matchMedia.activate('md');
expect(count).toEqual(2);
matchMedia.activate('gt-md');
matchMedia.activate('gt-lg');
matchMedia.activate('invalid');
expect(count).toEqual(2);
subscription.unsubscribe();
}));
it('can subscribe to built-in mediaQueries', inject(
[ObservableMedia, MatchMedia],
(media$, matchMedia) => {
let current: MediaChange;
expect(media$).toBeDefined();
let subscription = media$.subscribe((change: MediaChange) => {
current = change;
});
async(() => {
// Confirm initial match is for 'all'
expect(current).toBeDefined();
expect(current.matches).toBeTruthy();
expect(current.mediaQuery).toEqual('all');
try {
matchMedia.autoRegisterQueries = false;
// Activate mediaQuery associated with 'md' alias
matchMedia.activate('md');
expect(current.mediaQuery).toEqual(findMediaQuery('md'));
// Allow overlapping activations to be announced to observers
media$.filterOverlaps = false;
matchMedia.activate('gt-lg');
expect(current.mediaQuery).toEqual(findMediaQuery('gt-lg'));
matchMedia.activate('unknown');
expect(current.mediaQuery).toEqual(findMediaQuery('gt-lg'));
//.........这里部分代码省略.........
开发者ID:marffox,项目名称:flex-layout,代码行数:101,代码来源:observable-media.spec.ts
示例3: describe
describe('RegisterComponent', () => {
let fixture: ComponentFixture<RegisterComponent>;
let comp: RegisterComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ShinegatewayTestModule],
declarations: [RegisterComponent],
providers: [
Register,
{
provide: LoginModalService,
useValue: null
},
{
provide: Renderer,
useValue: null
},
{
provide: ElementRef,
useValue: null
}
]
}).overrideTemplate(RegisterComponent, '')
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(RegisterComponent);
comp = fixture.componentInstance;
comp.ngOnInit();
});
it('should ensure the two passwords entered match', () => {
comp.registerAccount.password = 'password';
comp.confirmPassword = 'non-matching';
comp.register();
expect(comp.doNotMatch).toEqual('ERROR');
});
it('should update success to OK after creating an account',
inject([Register, JhiLanguageService],
fakeAsync((service: Register, mockTranslate: MockLanguageService) => {
spyOn(service, 'save').and.returnValue(Observable.of({}));
comp.registerAccount.password = comp.confirmPassword = 'password';
comp.register();
tick();
expect(service.save).toHaveBeenCalledWith({
password: 'password',
langKey: 'en'
});
expect(comp.success).toEqual(true);
expect(comp.registerAccount.langKey).toEqual('en');
expect(mockTranslate.getCurrentSpy).toHaveBeenCalled();
expect(comp.errorUserExists).toBeNull();
expect(comp.errorEmailExists).toBeNull();
expect(comp.error).toBeNull();
})
)
);
it('should notify of user existence upon 400/login already in use',
inject([Register],
fakeAsync((service: Register) => {
spyOn(service, 'save').and.returnValue(Observable.throw({
status: 400,
json() {
return {type : LOGIN_ALREADY_USED_TYPE}
}
}));
comp.registerAccount.password = comp.confirmPassword = 'password';
comp.register();
tick();
expect(comp.errorUserExists).toEqual('ERROR');
expect(comp.errorEmailExists).toBeNull();
expect(comp.error).toBeNull();
})
)
);
it('should notify of email existence upon 400/email address already in use',
inject([Register],
fakeAsync((service: Register) => {
spyOn(service, 'save').and.returnValue(Observable.throw({
status: 400,
json() {
return {type : EMAIL_ALREADY_USED_TYPE}
}
}));
comp.registerAccount.password = comp.confirmPassword = 'password';
comp.register();
tick();
//.........这里部分代码省略.........
开发者ID:gavnel,项目名称:shine,代码行数:101,代码来源:register.component.spec.ts
示例4: describe
describe('MdInk', () => {
let builder: TestComponentBuilder;
function setup(template: string = defaultTemplate): Promise<ComponentFixture<TestComponent>> {
return builder
.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((fixture: ComponentFixture<TestComponent>) => {
fixture.detectChanges();
return fixture;
}).catch(console.error.bind(console));
}
beforeEach(inject([TestComponentBuilder], (tcb) => {
builder = tcb;
}));
describe('[md-ink]', () => {
it('should ink ripple when clicked', async(inject([], () => {
setup().then((fixture: ComponentFixture<TestComponent>) => {
let element: DebugElement = fixture.debugElement.query(By.css('[md-ink]'));
let save = Ink.rippleEvent;
let fired = false;
Ink.rippleEvent = () => {
fired = true;
return Promise.resolve();
};
let event = createEvent();
element.triggerEventHandler('mousedown', event);
expect(fired).toBe(true);
Ink.rippleEvent = save;
});
})));
it('should ink ripple without assertion mock', async(() => {
setup().then((fixture: ComponentFixture<TestComponent>) => {
let element: DebugElement = fixture.debugElement.query(By.css('[md-ink]'));
let event = createEvent();
element.triggerEventHandler('mousedown', event);
});
}));
it('should not ink ripple with md-no-ink attribute', async(inject([], () => {
let template = `<div md-ink md-no-ink></div>`;
setup(template).then((fixture: ComponentFixture<TestComponent>) => {
let element: DebugElement = fixture.debugElement.query(By.css('[md-ink]'));
let save = Ink.rippleEvent;
let fired = false;
Ink.rippleEvent = () => {
fired = true;
return Promise.resolve();
};
let event = createEvent();
element.triggerEventHandler('mousedown', event);
expect(fired).toBe(false);
Ink.rippleEvent = save;
});
})));
});
});
开发者ID:13812453806,项目名称:ng2-material,代码行数:67,代码来源:ink_spec.ts
示例5: describe
describe('Component: FileInput', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
TdFileInputBasicTestComponent,
TdFileInputModelTestComponent,
],
imports: [
FormsModule,
CovalentFileModule,
],
});
TestBed.compileComponents();
}));
it('should render content inside .td-file-input button',
async(inject([], () => {
let fixture: ComponentFixture<any> = TestBed.createComponent(TdFileInputBasicTestComponent);
let component: TdFileInputBasicTestComponent = fixture.debugElement.componentInstance;
component.multiple = false;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(fixture.debugElement.query(By.css('.td-file-input span'))).toBeTruthy();
});
})));
it('should mimic file selection and then clear it',
async(inject([], () => {
let fixture: ComponentFixture<any> = TestBed.createComponent(TdFileInputBasicTestComponent);
let component: TdFileInputBasicTestComponent = fixture.debugElement.componentInstance;
component.multiple = false;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.debugElement.query(By.directive(TdFileInputComponent)).componentInstance.handleSelect([{}]);
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.debugElement.query(By.directive(TdFileInputComponent)).componentInstance.clear();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(fixture.debugElement.query(By.directive(TdFileInputComponent)).componentInstance.value)
.toBeUndefined();
});
});
});
})));
it('should mimic file selection and then clear it by disabling it',
async(inject([], () => {
let fixture: ComponentFixture<any> = TestBed.createComponent(TdFileInputBasicTestComponent);
let component: TdFileInputBasicTestComponent = fixture.debugElement.componentInstance;
component.multiple = false;
component.disabled = false;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.debugElement.query(By.directive(TdFileInputComponent)).componentInstance.handleSelect([{}]);
component.disabled = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(fixture.debugElement.query(By.directive(TdFileInputComponent)).componentInstance.value).toBeUndefined();
});
});
})));
it('should mimic file (select) event',
async(inject([], () => {
let fixture: ComponentFixture<any> = TestBed.createComponent(TdFileInputBasicTestComponent);
let component: TdFileInputBasicTestComponent = fixture.debugElement.componentInstance;
component.multiple = false;
fixture.detectChanges();
expect(component.files).toBeUndefined();
fixture.whenStable().then(() => {
fixture.debugElement.query(By.directive(TdFileInputComponent)).componentInstance.handleSelect([{}]);
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(component.files).toBeTruthy();
});
});
})));
it('should mimic file selection event and check model',
async(inject([], () => {
let fixture: ComponentFixture<any> = TestBed.createComponent(TdFileInputModelTestComponent);
let component: TdFileInputModelTestComponent = fixture.debugElement.componentInstance;
component.multiple = false;
fixture.detectChanges();
expect(component.files).toBeUndefined();
fixture.whenStable().then(() => {
fixture.debugElement.query(By.directive(TdFileInputComponent)).componentInstance.handleSelect([{}]);
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(component.files).toBeTruthy();
});
});
})));
it('should mimic file selection event and check model and then clear it by disabling it',
async(inject([], () => {
let fixture: ComponentFixture<any> = TestBed.createComponent(TdFileInputModelTestComponent);
let component: TdFileInputModelTestComponent = fixture.debugElement.componentInstance;
//.........这里部分代码省略.........
开发者ID:Teradata,项目名称:covalent,代码行数:101,代码来源:file-input.component.spec.ts
示例6: describe
describe('SyndesisFormComponent test suite', () => {
const formModel = [
new DynamicCheckboxModel({ id: 'checkbox' }),
new DynamicCheckboxGroupModel({ id: 'checkboxGroup', group: [] }),
new DynamicDatePickerModel({ id: 'datepicker' }),
new DynamicEditorModel({ id: 'editor' }),
new DynamicFileUploadModel({ id: 'upload', url: '' }),
new DynamicFormArrayModel({ id: 'formArray', groupFactory: () => [] }),
new DynamicFormGroupModel({ id: 'formGroup', group: [] }),
new DynamicInputModel({ id: 'input', maxLength: 51 }),
new DynamicRadioGroupModel({ id: 'radioGroup' }),
new DynamicSelectModel({
id: 'select',
options: [{ value: 'One' }, { value: 'Two' }],
value: 'One'
}),
new DynamicSliderModel({ id: 'slider' }),
new DynamicSwitchModel({ id: 'switch' }),
new DynamicTextAreaModel({ id: 'textarea' }),
new DynamicTimePickerModel({ id: 'timepicker' })
];
const testModel = formModel[7] as DynamicInputModel;
let formGroup: FormGroup;
let fixture: ComponentFixture<SyndesisFormComponent>;
let component: SyndesisFormComponent;
let debugElement: DebugElement;
let testElement: DebugElement;
beforeEach(
async(() => {
TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
DynamicFormsCoreModule.forRoot(),
TextMaskModule,
TooltipModule.forRoot()
],
declarations: [SyndesisFormComponent]
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(SyndesisFormComponent);
component = fixture.componentInstance;
debugElement = fixture.debugElement;
});
})
);
beforeEach(
inject([DynamicFormService], (service: DynamicFormService) => {
formGroup = service.createFormGroup(formModel);
component.group = formGroup;
component.model = testModel;
component.ngOnChanges({
group: new SimpleChange(null, component.group, true),
model: new SimpleChange(null, component.model, true)
});
fixture.detectChanges();
testElement = debugElement.query(By.css(`input[id='${testModel.id}']`));
})
);
it('should initialize correctly', () => {
expect(component.context).toBeNull();
expect(component.control instanceof FormControl).toBe(true);
expect(component.group instanceof FormGroup).toBe(true);
expect(component.model instanceof DynamicFormControlModel).toBe(true);
expect(component.hasErrorMessaging).toBe(false);
expect(component.asBootstrapFormGroup).toBe(true);
expect(component.onControlValueChanges).toBeDefined();
expect(component.onModelDisabledUpdates).toBeDefined();
expect(component.onModelValueUpdates).toBeDefined();
expect(component.blur).toBeDefined();
expect(component.change).toBeDefined();
expect(component.focus).toBeDefined();
expect(component.onValueChange).toBeDefined();
expect(component.onFocusChange).toBeDefined();
expect(component.isValid).toBe(true);
expect(component.isInvalid).toBe(false);
expect(component.showErrorMessages).toBe(false);
expect(component.type).toEqual(SyndesisFormControlType.Input);
});
it('should have an input element', () => {
expect(testElement instanceof DebugElement).toBe(true);
});
it('should listen to native focus and blur events', () => {
spyOn(component, 'onFocusChange');
//.........这里部分代码省略.........
开发者ID:hawtio,项目名称:hawtio-ipaas,代码行数:101,代码来源:syndesis-form-control.component.spec.ts
示例7: describe
describe("DynamicKendoAutoCompleteComponent test suite", () => {
let testModel = new DynamicInputModel({id: "input", list: ["One", "Two", "Three"]}),
formModel = [testModel],
formGroup: FormGroup,
fixture: ComponentFixture<DynamicKendoAutoCompleteComponent>,
component: DynamicKendoAutoCompleteComponent,
debugElement: DebugElement,
testElement: DebugElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
NoopAnimationsModule,
TextMaskModule,
AutoCompleteModule,
DynamicFormsCoreModule
],
declarations: [DynamicKendoAutoCompleteComponent]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(DynamicKendoAutoCompleteComponent);
component = fixture.componentInstance;
debugElement = fixture.debugElement;
});
}));
beforeEach(inject([DynamicFormService], (service: DynamicFormService) => {
formGroup = service.createFormGroup(formModel);
component.group = formGroup;
component.model = testModel;
fixture.detectChanges();
testElement = debugElement.query(By.css(`kendo-autocomplete[id="${testModel.id}"]`));
}));
it("should initialize correctly", () => {
expect(component.control instanceof FormControl).toBe(true);
expect(component.group instanceof FormGroup).toBe(true);
expect(component.model instanceof DynamicInputModel).toBe(true);
expect(component.kendoAutoComplete instanceof AutoCompleteComponent).toBe(true);
expect(component.viewChild instanceof AutoCompleteComponent).toBe(true);
expect(component.blur).toBeDefined();
expect(component.change).toBeDefined();
expect(component.customEvent).toBeDefined();
expect(component.focus).toBeDefined();
expect(component.onBlur).toBeDefined();
expect(component.onChange).toBeDefined();
expect(component.onFocus).toBeDefined();
expect(component.hasFocus).toBe(false);
expect(component.isValid).toBe(true);
expect(component.isInvalid).toBe(false);
expect(component.showErrorMessages).toBe(false);
});
it("should have an kendo-autocomplete element", () => {
expect(testElement instanceof DebugElement).toBe(true);
});
it("should emit blur event", () => {
spyOn(component.blur, "emit");
component.onBlur(null);
expect(component.blur.emit).toHaveBeenCalled();
});
it("should emit change event", () => {
spyOn(component.change, "emit");
component.onChange(null);
expect(component.change.emit).toHaveBeenCalled();
});
it("should emit focus event", () => {
spyOn(component.focus, "emit");
component.onFocus(null);
expect(component.focus.emit).toHaveBeenCalled();
});
it("should emit custom event", () => {
//.........这里部分代码省略.........
开发者ID:udos86,项目名称:ng2-dynamic-forms,代码行数:101,代码来源:dynamic-kendo-autocomplete.component.spec.ts
示例8: describe
describe('RegisterComponent', () => {
let fixture: ComponentFixture<RegisterComponent>;
let comp: RegisterComponent;
beforeEach(
async(() => {
TestBed.configureTestingModule({
imports: [DemoTestModule],
declarations: [RegisterComponent]
})
.overrideTemplate(RegisterComponent, '')
.compileComponents();
})
);
beforeEach(() => {
fixture = TestBed.createComponent(RegisterComponent);
comp = fixture.componentInstance;
comp.ngOnInit();
});
it('should ensure the two passwords entered match', () => {
comp.registerAccount.password = 'password';
comp.confirmPassword = 'non-matching';
comp.register();
expect(comp.doNotMatch).toEqual('ERROR');
});
it(
'should update success to OK after creating an account',
inject(
[Register],
fakeAsync((service: Register) => {
spyOn(service, 'save').and.returnValue(of({}));
comp.registerAccount.password = comp.confirmPassword = 'password';
comp.register();
tick();
expect(service.save).toHaveBeenCalledWith({
password: 'password',
langKey: 'en'
});
expect(comp.success).toEqual(true);
expect(comp.registerAccount.langKey).toEqual('en');
expect(comp.errorUserExists).toBeNull();
expect(comp.errorEmailExists).toBeNull();
expect(comp.error).toBeNull();
})
)
);
it(
'should notify of user existence upon 400/login already in use',
inject(
[Register],
fakeAsync((service: Register) => {
spyOn(service, 'save').and.returnValue(
throwError({
status: 400,
error: { type: LOGIN_ALREADY_USED_TYPE }
})
);
comp.registerAccount.password = comp.confirmPassword = 'password';
comp.register();
tick();
expect(comp.errorUserExists).toEqual('ERROR');
expect(comp.errorEmailExists).toBeNull();
expect(comp.error).toBeNull();
})
)
);
it(
'should notify of email existence upon 400/email address already in use',
inject(
[Register],
fakeAsync((service: Register) => {
spyOn(service, 'save').and.returnValue(
throwError({
status: 400,
error: { type: EMAIL_ALREADY_USED_TYPE }
})
);
comp.registerAccount.password = comp.confirmPassword = 'password';
comp.register();
tick();
expect(comp.errorEmailExists).toEqual('ERROR');
expect(comp.errorUserExists).toBeNull();
expect(comp.error).toBeNull();
})
)
);
//.........这里部分代码省略.........
开发者ID:chrisdennis,项目名称:ehcache3-samples,代码行数:101,代码来源:register.component.spec.ts
示例9: describe
describe('ConnectionService', () => {
let MockHttp;
const HeaderServiceMock = {
createAuthHeaders: jasmine.createSpy('createAuthHeaders')
};
HeaderServiceMock.createAuthHeaders.and.returnValue('fake headers');
beforeEach(async(() => {
MockHttp = {
get: jasmine.createSpy('get'),
post: jasmine.createSpy('post'),
put: jasmine.createSpy('put'),
delete: jasmine.createSpy('delete')
};
MockHttp.get.and.returnValue('stuff');
MockHttp.post.and.returnValue('posted');
MockHttp.put.and.returnValue('putted');
MockHttp.delete.and.returnValue('things');
TestBed.configureTestingModule({
providers: [
ConnectionService,
{ provide: HeaderService, useValue: HeaderServiceMock },
MockBackend,
BaseRequestOptions,
{
provide: Http,
useValue: MockHttp
}
]
});
}));
it('should ...', inject([ConnectionService, HeaderService], (connectionService: ConnectionService) => {
expect(connectionService).toBeTruthy();
}));
it('should call get all connections endpoint', inject([ConnectionService, HeaderService], (service: ConnectionService) => {
service.apiBaseUrl = '/test/url/';
const response = service.getAll();
expect(response).toBe('stuff');
expect(MockHttp.get).toHaveBeenCalledWith('/test/url/connection');
}));
it('should call get connection endpoint', inject([ConnectionService, HeaderService], (service: ConnectionService) => {
service.apiBaseUrl = '/test/url/';
const response = service.getById(5);
expect(response).toBe('stuff');
expect(MockHttp.get).toHaveBeenCalledWith('/test/url/connection/5');
}));
it('should call save connection endpoint', inject([ConnectionService, HeaderService], (service: ConnectionService) => {
service.apiBaseUrl = '/test/url/';
const connection = new Connection('', '', '', '');
const response = service.save(connection);
expect(response).toBe('posted');
expect(MockHttp.post).toHaveBeenCalledWith('/test/url/connection', connection, { headers: 'fake headers' });
}));
it('should call update connection endpoint', inject([ConnectionService, HeaderService], (service: ConnectionService) => {
service.apiBaseUrl = '/test/url/';
const connection = new Connection('', '', '', '');
const response = service.update(5, connection);
expect(response).toBe('putted');
expect(MockHttp.put).toHaveBeenCalledWith('/test/url/connection/5', connection, { headers: 'fake headers' });
}));
it('should call remove connection endpoint', inject([ConnectionService, HeaderService], (service: ConnectionService) => {
service.apiBaseUrl = '/test/url/';
const response = service.remove(5);
expect(response).toBe('things');
expect(MockHttp.delete).toHaveBeenCalledWith('/test/url/connection/5', { headers: 'fake headers' });
}));
});
开发者ID:janiukjf,项目名称:JessicaJaniuk,代码行数:75,代码来源:connection.service.spec.ts
示例10: describe
describe('Service: Form, Angular Tests', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [NgxFormsService]
})
})
it('should inject the service instance...',
inject([NgxFormsService], (service: NgxFormsService) => {
expect(service).toBeTruthy()
}))
it('should return an input field...',
inject([NgxFormsService], (service: NgxFormsService) => {
const expected = {
key: 'inputKey',
type: 'input',
templateOptions: {
type: 'text',
label: 'Input',
placeholder: 'Input',
}
}
const field = service.input('inputKey', { placeholder: 'Input', label: 'Input' })
expect(field).toEqual(expected)
}))
it('should return an email field...',
inject([NgxFormsService], (service: NgxFormsService) => {
const expected = {
key: 'emailKey',
type: 'input',
templateOptions: {
type: 'email',
label: 'Email',
placeholder: 'Email',
}
}
const field = service.email('emailKey', { placeholder: 'Email', label: 'Email' })
expect(field).toEqual(expected)
}))
it('should return a password field...',
inject([NgxFormsService], (service: NgxFormsService) => {
const expected = {
key: 'passwordKey',
type: 'input',
templateOptions: {
type: 'password',
label: 'Password',
placeholder: 'Password',
}
}
const field = service.password('passwordKey', { placeholder: 'Password', label: 'Password' })
expect(field).toEqual(expected)
}))
it('should return a date field...',
inject([NgxFormsService], (service: NgxFormsService) => {
const expected = {
key: 'dateKey',
type: 'input',
templateOptions: {
type: 'date',
label: 'Date',
placeholder: 'Date',
}
}
const field = service.date('dateKey', { placeholder: 'Date', label: 'Date' })
expect(field).toEqual(expected)
}))
it('should return a textarea field...',
inject([NgxFormsService], (service: NgxFormsService) => {
const expected = {
key: 'textareaKey',
type: 'textarea',
templateOptions: {
type: 'text',
label: 'Text Area',
placeholder: 'Text Area',
}
}
const field = service.textarea('textareaKey', { placeholder: 'Text Area', label: 'Text Area' })
expect(field).toEqual(expected)
}))
it('should return a wysiwyg field...',
inject([NgxFormsService], (service: NgxFormsService) => {
const expected = {
key: 'wysiwygKey',
type: 'wysiwyg',
templateOptions: {
type: 'text',
label: 'Wysiwyg',
placeholder: 'Wysiwyg',
}
}
const field = service.wysiwyg('wysiwygKey', { placeholder: 'Wysiwyg', label: 'Wysiwyg' })
expect(field).toEqual(expected)
//.........这里部分代码省略.........
开发者ID:ngx-plus,项目名称:ngx-repo,代码行数:101,代码来源:ngx-forms.service.spec.ts
注:本文中的@angular/core/testing.inject函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论