I've got a component that uses the @Input()
annotation on an instance variable and I'm trying to write my unit test for the openProductPage()
method, but I'm a little lost at how I setup my unit test. I could make that instance variable public, but I don't think I should have to resort to that.
How do I setup my Jasmine test so that a mocked product is injected (provided?) and I can test the openProductPage()
method?
My component:
import {Component, Input} from "angular2/core";
import {Router} from "angular2/router";
import {Product} from "../models/Product";
@Component({
selector: "product-thumbnail",
templateUrl: "app/components/product-thumbnail/product-thumbnail.html"
})
export class ProductThumbnail {
@Input() private product: Product;
constructor(private router: Router) {
}
public openProductPage() {
let id: string = this.product.id;
this.router.navigate([“ProductPage”, {id: id}]);
}
}