本文整理汇总了TypeScript中angular2/testing.inject函数的典型用法代码示例。如果您正苦于以下问题:TypeScript inject函数的具体用法?TypeScript inject怎么用?TypeScript inject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了inject函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('ChampionsComponent', () => {
beforeEachProviders(() => [
RouteRegistry,
provide(Location, { useClass: SpyLocation }),
provide(ROUTER_PRIMARY_COMPONENT, { useValue: ChampionsComponent }),
provide(Router, { useClass: RootRouter }),
provide(RouteParams, { useValue: new RouteParams({ region: 'euw' }) }),
BaseRequestOptions,
MockBackend,
provide(Http, {
useFactory: (backend, defaultOptions) => {
return new Http(backend, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]
}),
LolApiService,
ChampionsComponent
]);
it('should call getData() on contruct', inject([RouteParams, Router, LolApiService], (routeParams, router, service) => {
spyOn(ChampionsComponent.prototype, 'getData');
expect(ChampionsComponent.prototype.getData).not.toHaveBeenCalled();
let component = new ChampionsComponent(routeParams, router, service);
expect(ChampionsComponent.prototype.getData).toHaveBeenCalled();
}));
it('should get champions', inject([MockBackend, ChampionsComponent, LolApiService], (mockBackend, component, service) => {
let mockResponse = new Response(new ResponseOptions({ status: 200, body: [{}] }));
mockBackend.connections.subscribe(
(connection: MockConnection) => {
connection.mockRespond(mockResponse);
});
expect(component.champions).not.toBeDefined();
component.getData();
return service.getChampions().toPromise().then( () => {
expect(component.champions).toBeDefined();
} );
}));
it('should not get champions', inject([MockBackend, ChampionsComponent, LolApiService], (mockBackend, component, service) => {
mockBackend.connections.subscribe(
(connection: MockConnection) => {
connection.mockError();
});
expect(component.champions).not.toBeDefined();
component.getData();
return service.getChampions().toPromise().catch(() => {
expect(component.champions).not.toBeDefined();
expect(component.error).toBeTruthy();
} );
}));
it('should have RouteParam region \'euw\'', inject([ChampionsComponent], (component) => {
expect(component.region).toEqual('euw');
}));
it('should navigate when enter is hit and one champion is available', inject([ChampionsComponent], (component) => {
spyOn(component.router, 'navigate');
expect(component.router.navigate).not.toHaveBeenCalled();
component.champions = { data: [{ key: 'Aatrox', name: 'Aatrox', tags: ['Fighter', 'Tank'], info: { 'defense': 4, 'magic': 3, 'difficulty': 4, 'attack': 8 } }] };
component.enterHit();
expect(component.router.navigate).toHaveBeenCalled();
}));
it('should not navigate when enter is hit and multiple champions are available', inject([ChampionsComponent], (component) => {
spyOn(component.router, 'navigate');
expect(component.router.navigate).not.toHaveBeenCalled();
component.champions = { data: [
{ key: 'Aatrox', name: 'Aatrox', tags: ['Fighter', 'Tank'], info: { defense: 4, magic: 3, difficulty: 4, attack: 8 } },
{ key: 'Thresh', name: 'Aatrox', tags: ['Fighter', 'Support'], info: { defense: 6, magic: 6, difficulty: 7, attack: 5 } }
]};
component.enterHit();
expect(component.router.navigate).not.toHaveBeenCalled();
}));
});
示例2: describe
describe('#meaningOfLife', () => {
it('should get the meaning of life', inject([CatalogoProductosApp], (app: CatalogoProductosApp) => {
expect(app.meaningOfLife()).toBe('The meaning of life is 42');
expect(app.meaningOfLife(22)).toBe('The meaning of life is 22');
}));
});
示例3: describe
describe('MdProgressBar', () => {
let builder: TestComponentBuilder;
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
builder = tcb;
}));
it('should apply a mode of "determinate" if no mode is provided.', (done: () => void) => {
builder
.overrideTemplate(TestApp, '<md-progress-bar></md-progress-bar>')
.createAsync(TestApp)
.then((fixture) => {
fixture.detectChanges();
let progressElement = fixture.debugElement.query(By.css('md-progress-bar'));
expect(progressElement.componentInstance.mode).toBe('determinate');
done();
});
});
it('should not modify the mode if a valid mode is provided.', (done: () => void) => {
builder
.overrideTemplate(TestApp, '<md-progress-bar mode="buffer"></md-progress-bar>')
.createAsync(TestApp)
.then((fixture) => {
fixture.detectChanges();
let progressElement = fixture.debugElement.query(By.css('md-progress-bar'));
expect(progressElement.componentInstance.mode).toBe('buffer');
done();
});
});
it('should define default values for value and bufferValue attributes', (done: () => void) => {
builder
.overrideTemplate(TestApp, '<md-progress-bar></md-progress-bar>')
.createAsync(TestApp)
.then((fixture) => {
fixture.detectChanges();
let progressElement = fixture.debugElement.query(By.css('md-progress-bar'));
expect(progressElement.componentInstance.value).toBe(0);
expect(progressElement.componentInstance.bufferValue).toBe(0);
done();
});
});
it('should clamp value and bufferValue between 0 and 100', (done: () => void) => {
builder
.overrideTemplate(TestApp, '<md-progress-bar></md-progress-bar>')
.createAsync(TestApp)
.then((fixture) => {
fixture.detectChanges();
let progressElement = fixture.debugElement.query(By.css('md-progress-bar'));
let progressComponent = progressElement.componentInstance;
progressComponent.value = 50;
expect(progressComponent.value).toBe(50);
progressComponent.value = 999;
expect(progressComponent.value).toBe(100);
progressComponent.value = -10;
expect(progressComponent.value).toBe(0);
progressComponent.bufferValue = -29;
expect(progressComponent.bufferValue).toBe(0);
progressComponent.bufferValue = 9;
expect(progressComponent.bufferValue).toBe(9);
progressComponent.bufferValue = 1320;
expect(progressComponent.bufferValue).toBe(100);
done();
});
});
it('should return the transform attribute for bufferValue and mode', (done: () => void) => {
builder
.overrideTemplate(TestApp, '<md-progress-bar></md-progress-bar>')
.createAsync(TestApp)
.then((fixture) => {
fixture.detectChanges();
let progressElement = fixture.debugElement.query(By.css('md-progress-bar'));
let progressComponent = progressElement.componentInstance;
expect(progressComponent.primaryTransform()).toBe('scaleX(0)');
expect(progressComponent.bufferTransform()).toBe(undefined);
progressComponent.value = 40;
expect(progressComponent.primaryTransform()).toBe('scaleX(0.4)');
expect(progressComponent.bufferTransform()).toBe(undefined);
progressComponent.value = 35;
progressComponent.bufferValue = 55;
expect(progressComponent.primaryTransform()).toBe('scaleX(0.35)');
expect(progressComponent.bufferTransform()).toBe(undefined);
progressComponent.mode = 'buffer';
expect(progressComponent.primaryTransform()).toBe('scaleX(0.35)');
expect(progressComponent.bufferTransform()).toBe('scaleX(0.55)');
//.........这里部分代码省略.........
示例4: describe
describe('Sidenav', () => {
let builder: TestComponentBuilder;
let service: SidenavService;
function setup(template: string = null): Promise<ITestFixture> {
let prep = template === null ?
builder.createAsync(TestComponent) :
builder.overrideTemplate(TestComponent, template).createAsync(TestComponent);
return prep.then((fixture: ComponentFixture) => {
fixture.detectChanges();
let debug = fixture.debugElement.query(By.css('md-sidenav'));
let cdebug = fixture.debugElement.query(By.css('md-sidenav-container'));
return {
fixture: fixture,
component: debug.componentInstance,
debug: debug,
cdebug: cdebug,
container: cdebug ? cdebug.componentInstance : null
};
}).catch(console.error.bind(console));
}
beforeEach(inject([TestComponentBuilder, SidenavService], (tcb, serv) => {
builder = tcb;
service = serv;
}));
describe('md-sidenav', () => {
it('should be created and destroyed', injectAsync([], () => {
return setup().then((api: ITestFixture) => api.fixture.destroy());
}));
it('should be registered and unregistered with SidenavService', injectAsync([], () => {
expect(service.find('test')).toBeNull();
return setup(`<md-sidenav name="test"></md-sidenav>`).then((api: ITestFixture) => {
expect(service.find('test')).not.toBeNull();
api.fixture.destroy();
expect(service.find('test')).toBeNull();
});
}));
describe('name', () => {
it('should default to "default"', injectAsync([], () => {
return setup().then((api: ITestFixture) => {
expect(api.component.name).toBe('default');
});
}));
});
describe('style', () => {
it('should default to over', injectAsync([], () => {
return setup().then((api: ITestFixture) => {
expect(api.component.style).toBe(SidenavStyle.OVER);
});
}));
it('should set to default when given an invalid value', injectAsync([], () => {
return setup(`<md-sidenav style="gangnam"></md-sidenav>`).then((api: ITestFixture) => {
expect(api.component.style).toBe(SidenavStyle.OVER);
});
}));
it('should accept "side" for content pushing', injectAsync([], () => {
return setup(`<md-sidenav style="side"></md-sidenav>`).then((api: ITestFixture) => {
expect(api.component.style).toBe(SidenavStyle.SIDE);
});
}));
});
describe('align', () => {
it('should default to "left"', injectAsync([], () => {
return setup().then((api: ITestFixture) => {
expect(api.component.align).toBe(SidenavAlignment.LEFT);
});
}));
it('should set to default when given an invalid value', injectAsync([], () => {
return setup(`<md-sidenav align="up"></md-sidenav>`).then((api: ITestFixture) => {
expect(api.component.align).toBe(SidenavAlignment.LEFT);
});
}));
it('should accept "side" for content pushing', injectAsync([], () => {
return setup(`<md-sidenav align="right"></md-sidenav>`).then((api: ITestFixture) => {
expect(api.component.align).toBe(SidenavAlignment.RIGHT);
});
}));
});
});
describe('md-sidenav-container', () => {
let template = `
<md-sidenav-container>
<md-sidenav name="menu"></md-sidenav>
<md-sidenav name="right" align="right"></md-sidenav>
</md-sidenav-container>`;
it('should be created and destroyed', injectAsync([], () => {
return setup(template).then((api: ITestFixture) => {
api.fixture.destroy();
});
}));
it('should maintain a query list of its children', injectAsync([], () => {
return setup(template).then((api: ITestFixture) => {
expect(api.container.children.length).toBe(2);
api.fixture.destroy();
});
//.........这里部分代码省略.........
示例5: describe
describe('#meaningOfLife', () => {
it('should get the meaning of life', inject([Ng2OrganApp], (app: Ng2OrganApp) => {
expect(app.meaningOfLife()).toBe('The meaning of life is 42');
expect(app.meaningOfLife(22)).toBe('The meaning of life is 22');
}));
});
示例6: describe
describe('UserSettingsServiceTests', () => {
function getDefaultUserSettingsObject() {
return getUserSettingsObject(
UserSettingsEnums.PointerSize.Small,
UserSettingsEnums.PointerType.Hand,
UserSettingsEnums.PointerColor.White,
UserSettingsEnums.BackgroundColor.InColor
);
}
function getUserSettingsObject(
pointerSize: UserSettingsEnums.PointerSize,
pointerType: UserSettingsEnums.PointerType,
pointerColor: UserSettingsEnums.PointerColor,
backgroundColor: UserSettingsEnums.BackgroundColor
): UserSettings {
var result = new UserSettings();
result.pointerSize = pointerSize;
result.pointerType = pointerType;
result.pointerColor = pointerColor;
result.backgroundColor = backgroundColor;
return result;
}
beforeEachProviders(() => [
BaseRequestOptions,
MockBackend,
provide(Http, {
useFactory: function(backend, defaultOptions) {
return new Http(backend, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]
}),
GlobalService,
UserSettingsService
]);
it('should have http', inject([UserSettingsService], (userSettingsService) => {
expect(!!userSettingsService.http).toEqual(true);
}));
it('getUserSettingsFor_givenValidUsername_shouldRetrievedDataFromTheHttpResponse',
inject([UserSettingsService, MockBackend], (userSettingsService: UserSettingsService, mockBackend) => {
// Arrange
var userSettingsObject = getDefaultUserSettingsObject();
mockBackend.connections.subscribe(
(connection: MockConnection) => {
connection.mockRespond(new Response(
new ResponseOptions({
body: JSON.stringify(userSettingsObject)
})));
});
// Act
userSettingsService.getUserSettingsFor('username').subscribe(
(data) => {
// Assert
expect(data.pointerSize).toBe(UserSettingsEnums.PointerSize.Small);
expect(data.pointerType).toBe(UserSettingsEnums.PointerType.Hand);
expect(data.pointerColor).toBe(UserSettingsEnums.PointerColor.White);
expect(data.backgroundColor).toBe(UserSettingsEnums.BackgroundColor.InColor);
},
(error) => {
fail(error);
}
);
}));
it('saveUserSettingsForUser_givenValidUsernameAndUserSettings_shouldRetrievedDataFromTheHttpResponse',
inject([UserSettingsService, MockBackend], (userSettingsService: UserSettingsService, mockBackend) => {
// Arrange
var userSettingsObject = getDefaultUserSettingsObject();
mockBackend.connections.subscribe(
(connection: MockConnection) => {
connection.mockRespond(new Response(
new ResponseOptions({
body: JSON.stringify(userSettingsObject)
})));
});
// Act
userSettingsService.saveUserSettingsForUser('username', userSettingsObject).subscribe(
(data) => {
// Assert
expect(data.pointerSize).toBe(UserSettingsEnums.PointerSize.Small);
expect(data.pointerType).toBe(UserSettingsEnums.PointerType.Hand);
expect(data.pointerColor).toBe(UserSettingsEnums.PointerColor.White);
expect(data.backgroundColor).toBe(UserSettingsEnums.BackgroundColor.InColor);
},
(error) => {
fail(error);
}
);
}));
});
示例7: describe
describe('when signed in', () => {
let loginService:LoginService;
beforeEach(inject([LoginService], _ => {
loginService = _;
}));
beforeEach(signin({id: 1, email: 'test@test.com'}));
beforeEach(createCmp);
it('can be shown', () => {
expect(cmpDebugElement).toBeTruthy();
});
it('shows a nav link to home', (done) => {
const link = DOM.querySelector(cmpDebugElement.nativeElement, '#navbar li.home>a');
expect(link).toBeTruthy();
link.click();
ctx.router.subscribe(() => {
ctx.fixture.detectChanges();
expect(ctx.location.path()).toEqual('/home');
expect(link.parentElement.classList).toContain('active');
done();
});
});
it('does not show a nav link to top', () => {
const link = DOM.querySelector(cmpDebugElement.nativeElement, '#navbar li.top>a');
expect(link).toBeNull();
});
it('shows a nav link to users', (done) => {
const link = DOM.querySelector(cmpDebugElement.nativeElement, '#navbar li.users>a');
expect(link).toBeTruthy();
link.click();
ctx.router.subscribe(() => {
ctx.fixture.detectChanges();
expect(ctx.location.path()).toEqual('/users');
expect(link.parentElement.classList).toContain('active');
done();
});
});
it('shows a nav link to help', (done) => {
const link = DOM.querySelector(cmpDebugElement.nativeElement, '#navbar li.help>a');
expect(link).toBeTruthy();
link.click();
ctx.router.subscribe(() => {
ctx.fixture.detectChanges();
expect(ctx.location.path()).toEqual('/help');
expect(link.parentElement.classList).toContain('active');
done();
});
});
it('shows a nav link to profile', (done) => {
const link = DOM.querySelector(cmpDebugElement.nativeElement, '#navbar li.profile>a');
expect(link).toBeTruthy();
link.click();
ctx.router.subscribe(() => {
ctx.fixture.detectChanges();
expect(ctx.location.path()).toEqual('/users/me');
done();
});
});
describe('navigate to settings', () => {
beforeEach(inject([UserService], userService => {
spyOn(userService, 'get').and.returnValue(Observable.of({}));
}));
it('shows a nav link to settings', (done) => {
const link = DOM.querySelector(cmpDebugElement.nativeElement, '#navbar li.settings>a');
expect(link).toBeTruthy();
link.click();
ctx.router.subscribe(() => {
ctx.fixture.detectChanges();
expect(ctx.location.path()).toEqual('/users/me/edit');
done();
});
});
});
it('shows a nav link to logout', () => {
const link = DOM.querySelector(cmpDebugElement.nativeElement, '#navbar li.logout>a');
expect(link).toBeTruthy();
spyOn(loginService, 'logout');
link.click();
expect(loginService.logout).toHaveBeenCalled();
});
}); // when signed in
示例8: describe
describe('Service: Order Service', ()=>{
let mockbackend: MockBackend, service: OrderService;
beforeEachProviders(() => [
MockBackend,
BaseRequestOptions,
provide(Http, {
useFactory: (backend, options) => new Http(backend, options),
deps: [MockBackend, BaseRequestOptions]
}),
OrderService,
]);
beforeEach(inject([MockBackend, OrderService], (_mockbackend, _service) => {
mockbackend = _mockbackend;
service = _service;
}));
it('contains empty order', () => {
expect(service.order).not.toEqual(null);
});
it('calculates total', () => {
let dish: Dish = {
id: 1,
url: 'stub',
price: 20,
}
let dish2: Dish = {
id: 2,
url: 'stub',
price: 10,
}
service.add(dish, 2);
service.add(dish2, 3);
expect(service.total).toEqual(dish.price * 2 + dish2.price * 3);
});
it('will not submit empty order', done=>{
service.saveOrder().subscribe(
() => { fail('Should not success')},
()=> {
expect(true).toEqual(true);
done();
},
()=>{done()}
);
})
it('will assign id after successful submit', done => {
mockbackend.connections.subscribe(connection => {
connection.mockRespond(new Response({ body: JSON.stringify({'_id': 20})}));
});
let dish: Dish = {
id: 1,
url: 'stub',
price: 20,
}
service.add(dish, 1);
service.saveOrder().subscribe(
(success) => {
expect(service.order.id).toEqual(20);
done();
},
(err) => {
console.log(err);
fail('Should not fail');
done();
},
() => {
done();
})
});
});
示例9: describe
describe('UserSettingsComponentTests', () => {
beforeEachProviders(() => [
AlertingService,
UserSettingsColorsService,
provide(ImagesService, { useClass: ImagesServiceMock }),
UserSettingsComponent
]);
it('setAvailablePointerImages_givenAvailableImageService_shouldSetAllPointerImages',
inject([UserSettingsComponent], (instance) => {
// Arrange
let allPointerImagesLocal = ['./app/assets/images/pointer/small.png', './app/assets/images/pointer/big.png'];
spyOn(instance.imagesService, 'getPointerImages').and.callThrough();
// Act
instance.setAvailablePointerImages();
// Assert
expect(instance.allPointerImages).toEqual(allPointerImagesLocal);
expect(instance.imagesService.getPointerImages).toHaveBeenCalled();
}));
it('setAvailablePointerImages_givenUnavailableImageService_shouldThrowAlertForDanger',
inject([UserSettingsComponent], (instance) => {
// Arrange
spyOn(instance.imagesService, 'getPointerImages').and.callFake(() => { return Observable.throw(new Error()); });
spyOn(instance.alertingService, 'addDanger').and.callFake(() => { });
// Act
instance.setAvailablePointerImages();
// Assert
expect(instance.imagesService.getPointerImages).toHaveBeenCalled();
expect(instance.alertingService.addDanger).toHaveBeenCalledWith('Грешка при вчитување на покажувачите.');
}));
it('setBackgroundColorAndPointerColors_givenBlackAndWhiteBgColor_shouldSetBgColorAndLoadPointerColors',
injectAsync([TestComponentBuilder], (tcb) => {
return tcb.overrideTemplate(UserSettingsComponent, '').createAsync(UserSettingsComponent).then((fixture) => {
// Arrange
let bgColor: BackgroundColor = BackgroundColor.BlackAndWhite;
let instance = fixture.componentInstance;
instance.userSettings = new UserSettings();
instance.userSettings.backgroundColor = BackgroundColor.InColor;
fixture.detectChanges();
spyOn(instance.pointerColorService, 'getPointerColors').and.callFake(() => { });
// Act
instance.setBackgroundColorAndPointerColors(bgColor);
// Assert
expect(instance.userSettings.backgroundColor).toEqual(bgColor);
expect(instance.pointerColorService.getPointerColors).toHaveBeenCalledWith(bgColor);
});
}));
it('selectBackgroundColor_givenBlackAndWhiteBgColor_shouldCallSetBackgroundMethodAndSetPointerDefaults',
injectAsync([TestComponentBuilder], (tcb) => {
return tcb.overrideTemplate(UserSettingsComponent, '').createAsync(UserSettingsComponent).then((fixture) => {
// Arrange
let nonDefaultPointerColor: PointerColor = PointerColor.Blue;
let defaultPointerColor: PointerColor = PointerColor.White;
let bgColor: BackgroundColor = BackgroundColor.BlackAndWhite;
let instance = fixture.componentInstance;
instance.userSettings = new UserSettings();
instance.userSettings.backgroundColor = BackgroundColor.InColor;
instance.userSettings.pointerColor = nonDefaultPointerColor;
fixture.detectChanges();
spyOn(instance, 'setBackgroundColorAndPointerColors').and.callThrough();
spyOn(instance, 'selectPointerColor').and.callThrough();
// Act
instance.selectBackgroundColor(bgColor);
// Assert
expect(instance.setBackgroundColorAndPointerColors).toHaveBeenCalledWith(bgColor);
expect(instance.selectPointerColor).toHaveBeenCalledWith(defaultPointerColor);
});
}));
it('selectPointerColor_givenPointerColor_shouldSetPointerColor',
injectAsync([TestComponentBuilder], (tcb) => {
return tcb.overrideTemplate(UserSettingsComponent, '').createAsync(UserSettingsComponent).then((fixture) => {
// Arrange
let defaultPointerColor: PointerColor = PointerColor.White;
let newPointerColor: PointerColor = PointerColor.Blue;
let instance = fixture.componentInstance;
instance.userSettings = new UserSettings();
instance.userSettings.pointerColor = defaultPointerColor;
fixture.detectChanges();
// Act
instance.selectPointerColor(newPointerColor);
// Assert
expect(instance.userSettings.pointerColor).toEqual(newPointerColor);
});
}));
it('selectPointerSize_givenPointerSize_shouldSetPointerSize',
//.........这里部分代码省略.........
示例10: describe
describe('Feed', () => {
var ctx:TestContext;
var cmpDebugElement:DebugElement;
var micropostService:MicropostService;
beforeEachProviders(() => [
APP_TEST_PROVIDERS,
provide(ROUTER_PRIMARY_COMPONENT, {useValue: App}),
]);
beforeEach(createTestContext(_ => ctx = _));
beforeEach(inject([MicropostService], _ => {
micropostService = _;
}));
beforeEach(() => jasmine.clock().mockDate(new Date(24 * 60 * 60 * 1000)));
function createCmp(done) {
ctx.backend.connections.subscribe(conn => {
conn.mockRespond(dummyResponse);
});
ctx.init(TestCmp)
.finally(done)
.subscribe(() => {
cmpDebugElement = ctx.fixture.debugElement.query(By.directive(Feed));
});
}
beforeEach(createCmp);
it('can show feed', () => {
expect(cmpDebugElement).toBeTruthy();
const cmp:Feed = cmpDebugElement.componentInstance;
expect(cmp.feed.length).toEqual(2);
const el = cmpDebugElement.nativeElement;
expect(DOM.querySelectorAll(el, 'li .content').length).toEqual(2);
const avatarLink = DOM.querySelector(el, 'li>a');
expect(avatarLink.getAttribute('href')).toEqual('/users/1');
const gravatarDebugElement = cmpDebugElement.query(By.directive(Gravatar));
expect(gravatarDebugElement).toBeTruthy();
expect(gravatarDebugElement.componentInstance.email).toEqual('test1@test.com');
expect(gravatarDebugElement.componentInstance.alt).toEqual('test user1');
const userLink = DOM.querySelector(el, '.user>a');
expect(userLink.innerHTML).toEqual("test user1");
expect(userLink.getAttribute('href')).toEqual('/users/1');
const content = DOM.querySelector(el, '.content');
expect(content.innerHTML).toEqual('content1');
const timestamp = DOM.querySelector(el, '.timestamp');
expect(timestamp.innerText).toMatch(/1 day ago/);
const deleteLinks = DOM.querySelectorAll(el, '.delete');
expect(deleteLinks[0]).toBeTruthy();
expect(deleteLinks[1]).toBeFalsy();
});
it('does not delete micropost when not confirmed', () => {
const deleteLink = DOM.querySelector(cmpDebugElement.nativeElement, '.delete');
spyOn(window, 'confirm').and.returnValue(false);
spyOn(micropostService, 'delete');
deleteLink.click();
expect(micropostService.delete).not.toHaveBeenCalled();
});
it('deletes micropost when confirmed', done => {
const cmp:Feed = cmpDebugElement.componentInstance;
const testCmp:TestCmp = ctx.fixture.debugElement.componentInstance;
const deleteLink = DOM.querySelector(cmpDebugElement.nativeElement, '.delete');
spyOn(window, 'confirm').and.returnValue(true);
spyOn(cmp, 'list');
spyOn(testCmp, 'listenDeleted');
ObservableWrapper.subscribe(cmp.deleted, () => {
expect(cmp.list).toHaveBeenCalled();
expect(testCmp.listenDeleted).toHaveBeenCalled();
done();
});
deleteLink.click();
});
});