This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Can be run with a file like this: | |
// node convert-to-jest.js src/app/home/search/search.component.spec.ts | |
var fs = require('fs'); | |
var filename = process.argv[2]; | |
if (!filename) { | |
let specs = require('glob').sync('src/**/*.spec.ts'); | |
for (spec of specs) { | |
if (!spec.includes('pact')) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"lastUpload":"2020-08-20T09:11:43.945Z","extensionVersion":"v3.4.3"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addMovie(movie: Movie): void { | |
this.favoriteMovieService.addMovie(movie); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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)" | |
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('SearchComponent', () => { | |
beforeEach(() => { | |
fixture.detectChanges(); | |
}); | |
it('should show the search component', () => { | |
const searchComponents = fixture.debugElement.queryAll(By.directive(SearchMovieComponent)); | |
expect(searchComponents.length).toEqual(1); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
deleteMovie(movie: Movie): void { | |
this.favoriteMovieService.deleteMovie(movie); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ng-container *ngIf="favoriteMovies$ | async; let favoriteMovies"> | |
<kpd-favorite-movie *ngFor="let movie of favoriteMovies" [favoriteMovie]="movie"> | |
</kpd-favorite-movie> | |
</ng-container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |