Skip to content

Instantly share code, notes, and snippets.

💭
💻 🐵

Catalin Ciubotaru FunnyGhost

💭
💻 🐵
Block or report user

Report or block FunnyGhost

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View favorite-movies.component.ts
addMovie(movie: Movie): void {
this.favoriteMovieService.addMovie(movie);
}
View favorite-movies.component.html
<h1>Favorite movies</h1>
<kpd-search-movie (addMovie)="addMovie($event)"></kpd-search-movie>
<ng-container *ngIf="favoriteMovies$ | async; let favoriteMovies">
<kpd-favorite-movie
*ngFor="let movie of favoriteMovies"
[favoriteMovie]="movie"
(deleteMovie)="deleteMovie($event)"
>
View favorite-movies.component.spec.ts
describe('SearchComponent', () => {
beforeEach(() => {
fixture.detectChanges();
});
it('should show the search component', () => {
const searchComponents = fixture.debugElement.queryAll(By.directive(SearchMovieComponent));
expect(searchComponents.length).toEqual(1);
});
View favorite-movies.component.ts
deleteMovie(movie: Movie): void {
this.favoriteMovieService.deleteMovie(movie);
}
View favorite-movies.component.html
<ng-container *ngIf="favoriteMovies$ | async; let favoriteMovies">
<kpd-favorite-movie
*ngFor="let movie of favoriteMovies"
[favoriteMovie]="movie"
(deleteMovie)="deleteMovie($event)"
>
</kpd-favorite-movie>
</ng-container>
View favorite-movies.component.spec.ts
it('should delete a favorite movie when the user wants to', () => {
jest.spyOn(favoriteMovieService, 'deleteMovie');
const favoriteMovieToDelete = favoriteMoviesToUse[0];
const componentToDelete = fixture.debugElement.queryAll(
By.directive(FavoriteMovieComponent)
)[0].componentInstance as FavoriteMovieComponent;
componentToDelete.deleteMovie.emit(favoriteMovieToDelete);
expect(favoriteMovieService.deleteMovie).toHaveBeenCalledWith(favoriteMovieToDelete);
View favorite-movies.component.html
<ng-container *ngIf="favoriteMovies$ | async; let favoriteMovies">
<kpd-favorite-movie *ngFor="let movie of favoriteMovies" [favoriteMovie]="movie">
</kpd-favorite-movie>
</ng-container>
View favorite-movies.component.spec.ts
it('should show all the favorite movies', () => {
const movieComponents = fixture.debugElement.queryAll(By.directive(FavoriteMovieComponent));
expect(movieComponents.length).toEqual(favoriteMoviesToUse.length);
const movieComponentsInputs = movieComponents.map(
htmlComponent => (htmlComponent.componentInstance as FavoriteMovieComponent).favoriteMovie
);
expect(movieComponentsInputs).toEqual(favoriteMoviesToUse);
});
View favorite-movies.component.spec.ts
declarations: [FavoriteMoviesComponent, MockComponent(FavoriteMovieComponent)],
View favorite-movies.component.html
<ng-container *ngIf="favoriteMovies$ | async; let favoriteMovies">
<kpd-favorite-movie *ngFor="let movie of favoriteMovies"> </kpd-favorite-movie>
</ng-container>
You can’t perform that action at this time.