Skip to content

Instantly share code, notes, and snippets.

describe('CatService', () => {
let classUnderTest: CatService;
beforeAll(() => {
classUnderTest = new CatService();
});
it('returns undefined for an unknown cat breed', () => {
const result = classUnderTest.getBreed('Maine Coon');
productsData$ = this.loadProductsClicks$.pipe(
switchMap(() => this.http.get('/api/products').pipe(trackRemoteData()))
);
@Component({
selector: 'app-products',
template: `
<button (click)="loadProducts()">Load Products</button>
<ng-container *ngIf="productsData$ | async as productsData">
<ng-container *ngIf="productsData.state === 'loading'">
Loading...
</ng-container>
@Component({
selector: 'app-products',
template: `
<button (click)="loadProducts()">Load Products</button>
<ng-container *ngIf="productsData.state === 'loading'">
Loading...
</ng-container>
<ng-container *ngIf="productsData.state === 'error'">
type RemoteData<T = unknown, E = Error> =
| NotAskedState<T>
| LoadingState<T>
| SuccessState<T>
| ErrorState<T, E>;
export interface LoadingState<T = unknown> {
readonly state: 'loading';
readonly isLoading: true;
readonly value?: T;
function loadingState(): LoadingState {
return {
state: 'loading',
isLoading: true,
value,
};
}
function successState<T>(value?: T): SuccessState<T> {
return {
interface RemoteData<T, E> {
state: 'notAsked' | 'loading' | 'success' | 'error';
isLoading: boolean;
value?: T;
error?: E;
}
@Component({
selector: 'app-products',
template: `
<button (click)="loadProducts()">Load Products</button>
<ng-container *ngIf="isLoading else doneLoading">
Loading...
</ng-container>
<ng-template #doneLoading>
@Component({
selector: 'app-products',
template: `
<button (click)="loadProducts()">Load Products</button>
<ng-container *ngIf="isLoading">
Loading...
</ng-container>
<ng-container *ngIf="!isLoading">
@Component({
selector: 'app-products',
template: `
<button (click)="loadProducts()">Load Products</button>
<ng-container *ngFor="let product of products">
<app-product [product]="product"></app-product>
</ng-container>
`
})