Skip to content

Commit

Permalink
Mock storage service in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jantoun-scottlogic committed Aug 5, 2024
1 parent 7969e63 commit 7645c27
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { CarbonEstimatorFormComponent } from './carbon-estimator-form.component';
import { StorageService } from '../services/storage.service';

class MockStorageService {
storage: Record<string, string> = {};

get(key: string): string | null {
return this.storage[key] || null;
}

set(key: string, value: string): void {
this.storage[key] = value;
}
}

describe('CarbonEstimatorFormComponent', () => {
let component: CarbonEstimatorFormComponent;
Expand All @@ -9,6 +22,7 @@ describe('CarbonEstimatorFormComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [CarbonEstimatorFormComponent],
providers: [{ provide: StorageService, useClass: MockStorageService }],
}).compileComponents();

fixture = TestBed.createComponent(CarbonEstimatorFormComponent);
Expand Down

0 comments on commit 7645c27

Please sign in to comment.