Skip to content

Commit

Permalink
Merge pull request #15 from FelipeDuarteLuna/03-01-24
Browse files Browse the repository at this point in the history
01/01/2024 - Gerenciamento de estado
  • Loading branch information
FelipeDuarteLuna authored Jan 22, 2024
2 parents 1df5d2f + 5cf2dc2 commit 1dcdb0b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { CartService } from './cart.service';

describe('CartService', () => {
let service: CartService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(CartService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root',
})
export class CartService {
constructor() {}
}
41 changes: 37 additions & 4 deletions src/app/interceptors/http-errors/http-errors.interceptor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,51 @@
import { TestBed } from '@angular/core/testing';

import { HttpErrorsInterceptor } from './http-errors.interceptor';
import { HTTP_INTERCEPTORS, HttpClient } from '@angular/common/http';
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
import {
HttpClientTestingModule,
HttpTestingController,
} from '@angular/common/http/testing';

describe('HttpErrorsInterceptor', () => {
beforeEach(() =>
let httpClient: HttpClient;
let httpMock: HttpTestingController;
let matSnackBar: MatSnackBar;

beforeEach(() => {
TestBed.configureTestingModule({
providers: [HttpErrorsInterceptor],
})
);
imports: [HttpClientTestingModule, MatSnackBarModule],
providers: [
HttpErrorsInterceptor,
{
provide: HTTP_INTERCEPTORS,
useClass: HttpErrorsInterceptor,
multi: true,
},
],
});

httpClient = TestBed.inject(HttpClient);
httpMock = TestBed.inject(HttpTestingController);
matSnackBar = TestBed.inject(MatSnackBar);
});

it('should be created', () => {
const interceptor: HttpErrorsInterceptor = TestBed.inject(
HttpErrorsInterceptor
);
expect(interceptor).toBeTruthy();
});

it('should open notification on http error', () => {
jest.spyOn(matSnackBar, 'open');
httpClient.get('/test').subscribe();

const request = httpMock.expectOne('/test');
request.error(new ProgressEvent('error'));

expect(matSnackBar.open).toHaveBeenCalled();
expect(request.request.headers.has('x-access-token')).toBe(true);
});
});

0 comments on commit 1dcdb0b

Please sign in to comment.