Skip to content

Instantly share code, notes, and snippets.

@Swiip
Created July 5, 2016 08:07
Show Gist options
  • Save Swiip/240e4d145cb0465810ca3a75a6aec89d to your computer and use it in GitHub Desktop.
Save Swiip/240e4d145cb0465810ca3a75a6aec89d to your computer and use it in GitHub Desktop.
Test HomeComponent
/* tslint:disable:no-unused-variable */
// import { By } from '@angular/platform-browser';
// import { DebugElement } from '@angular/core';
import { async, inject } from '@angular/core/testing';
import { TestComponentBuilder, ComponentFixture } from '@angular/compiler/testing';
import { HomeComponent } from './home.component';
describe('Component: Home', () => {
let tcb: TestComponentBuilder;
beforeEach(inject([TestComponentBuilder], (_tcb: TestComponentBuilder) => {
tcb = _tcb;
}));
it('should create an instance', async(inject([], () => {
return tcb
.createAsync(HomeComponent)
.then((fixture: ComponentFixture<any>) => {
console.log('coucou', fixture);
expect(true).toBeFalsy();
});
})));
});
import { Component, OnInit, Inject } from '@angular/core';
import { Product } from '../model/product';
import { ProductComponent } from '../product/product.component';
import { FooterComponent } from '../footer/footer.component';
import { ProductService } from '../services/ProductService';
import { CustomerService } from '../services/CustomerService';
import { OrderByPipe } from '../order-by.pipe';
@Component({
moduleId: module.id,
selector: 'app-home',
templateUrl: 'home.component.html',
styleUrls: ['home.component.css'],
directives: [ProductComponent, FooterComponent],
pipes: [OrderByPipe]
})
export class HomeComponent implements OnInit {
constructor(
public productService: ProductService,
public customerService: CustomerService,
@Inject('hello') public hello: string
) {}
ngOnInit() {
this.productService.getProducts();
}
addToBasket(product:Product): void {
this.customerService.addProduct(product)
.subscribe(() => this.productService.decreaseStock(product));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment