Currently, I am working on a component that utilizes the @Input()
annotation on an instance variable. As part of this process, I am attempting to write a unit test for the openProductPage()
method. However, I'm feeling a bit uncertain about how to set up my unit test effectively. Although I could make the instance variable public, I believe there should be a better solution.
Can someone provide guidance on how to configure my Jasmine test so that a mocked product is injected or provided? My ultimate goal is to test the functionality of the openProductPage()
method.
Here's a snippet of 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}]);
}
}