-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
126 additions
and
65 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,29 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { of } from 'rxjs'; | ||
import { AppComponent } from './app.component'; | ||
import { WithingsService } from './withings.service'; | ||
|
||
describe('AppComponent', () => { | ||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ | ||
RouterTestingModule | ||
], | ||
declarations: [ | ||
AppComponent | ||
], | ||
}).compileComponents(); | ||
async function setup() { | ||
const mockWithingsService = jasmine.createSpyObj('WithingsService', { | ||
sync: of(), | ||
}); | ||
await TestBed.configureTestingModule({ | ||
declarations: [AppComponent], | ||
providers: [{ provide: WithingsService, useValue: mockWithingsService }], | ||
}).compileComponents(); | ||
|
||
it('should create the app', () => { | ||
const fixture = TestBed.createComponent(AppComponent); | ||
const app = fixture.componentInstance; | ||
expect(app).toBeTruthy(); | ||
}); | ||
const fixture = TestBed.createComponent(AppComponent); | ||
fixture.detectChanges(); | ||
|
||
it(`should have as title 'client'`, () => { | ||
const fixture = TestBed.createComponent(AppComponent); | ||
const app = fixture.componentInstance; | ||
expect(app.title).toEqual('client'); | ||
}); | ||
return { | ||
fixture, | ||
element: fixture.nativeElement as HTMLElement | ||
}; | ||
} | ||
|
||
it('should render title', () => { | ||
const fixture = TestBed.createComponent(AppComponent); | ||
fixture.detectChanges(); | ||
const compiled = fixture.nativeElement as HTMLElement; | ||
expect(compiled.querySelector('.content span')?.textContent).toContain('client app is running!'); | ||
describe('AppComponent', () => { | ||
it('should render loading state', async () => { | ||
const { element } = await setup(); | ||
expect(element.textContent).toEqual('Loading...'); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
import { of } from 'rxjs'; | ||
import { WeightService } from './weight.service'; | ||
import { WeightResponse } from './types'; | ||
|
||
async function setup() { | ||
const mockHttpClient = jasmine.createSpyObj('HttpClient', { | ||
get: of({ weight: 89.6 } as WeightResponse ), | ||
}); | ||
|
||
const service = new WeightService(mockHttpClient); | ||
|
||
return { | ||
service, | ||
}; | ||
} | ||
|
||
describe('WeightService', () => { | ||
it('should be created', async () => { | ||
const { service } = await setup() | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { WeightComponent } from './weight.component'; | ||
import { WeightService } from '../weight.service'; | ||
import { of } from 'rxjs'; | ||
|
||
describe('WeightComponent', () => { | ||
let component: WeightComponent; | ||
let fixture: ComponentFixture<WeightComponent>; | ||
async function setup() { | ||
const mockWeightService = jasmine.createSpyObj('WeightService', { | ||
getWeight: of(), | ||
}); | ||
await TestBed.configureTestingModule({ | ||
declarations: [WeightComponent], | ||
providers: [{ provide: WeightService, useValue: mockWeightService }], | ||
}).compileComponents(); | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ WeightComponent ] | ||
}) | ||
.compileComponents(); | ||
const fixture = TestBed.createComponent(WeightComponent); | ||
fixture.detectChanges(); | ||
|
||
fixture = TestBed.createComponent(WeightComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
return { | ||
fixture, | ||
element: fixture.nativeElement as HTMLElement | ||
}; | ||
} | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
describe('WeightComponent', () => { | ||
it('should create', async () => { | ||
const { element } = await setup(); | ||
expect(element.textContent).toEqual('Loading...') | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { of } from 'rxjs'; | ||
import { WithingsService } from './withings.service'; | ||
|
||
describe('WithingsService', () => { | ||
let service: WithingsService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(WithingsService); | ||
async function setup() { | ||
const mockHttpClient = jasmine.createSpyObj('HttpClient', { | ||
post: of(), | ||
}); | ||
|
||
it('should be created', () => { | ||
const service = new WithingsService(mockHttpClient); | ||
|
||
return { | ||
service, | ||
}; | ||
} | ||
|
||
describe('WithingsService', () => { | ||
it('should be created', async () => { | ||
const { service } = await setup() | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |