Unmapped Tests for Config Initializer
bibble235 opened this issue · 1 comments
bibble235 commented
Describe the Bug
When I create a config initalizer it shows up as unmapped test
- A clear and concise description of what the bug is.
import { ConfigService } from './config.service'
export const ConfigServiceInitializer = (configService: ConfigService) => {
return (): Promise<boolean> => {
return new Promise<boolean>(
(resolve: (result: boolean) => void, reject: (result: boolean) => void) => {
configService.load().subscribe({
next: () => {
resolve(true)
},
error: (error) => reject(error),
})
},
)
}
}
And the test
import { TestBed, waitForAsync } from '@angular/core/testing'
import { of } from 'rxjs'
import { tap } from 'rxjs/operators'
import { ConfigModule, ConfigService, ConfigServiceInitializer } from '.'
import { HttpClientModule } from '@angular/common/http'
import { HttpClientTestingModule } from '@angular/common/http/testing'
describe('ConfigServiceInitializer', () => {
const mockedConfigService: any = jasmine.createSpyObj('ConfigService', ['load'])
let configService: ConfigService
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientModule, ConfigModule, HttpClientTestingModule],
})
configService = TestBed.inject(ConfigService)
})
it(
'should resolve the promise',
waitForAsync(() => {
mockedConfigService.load.and.returnValue(of({}))
ConfigServiceInitializer(configService)().then((status) => {
expect(status).toBe(true)
})
}),
)
it(
'should reject the promise',
waitForAsync(() => {
mockedConfigService.load.and.returnValue(
of({}).pipe(
tap(() => {
throw Error('failure')
}),
),
)
ConfigServiceInitializer(configService)().then(
() => {},
(error) => {
expect(error.message).toEqual('failure')
},
)
}),
)
})
Steps to Reproduce the Behavior
- Create an Angular project v13.0.4
- Create an initializer (config.service.initializer.ts)
- Create test (config.service.initializer.spec.ts)
4.Go to Test Explorer
Describe the Expected Behavior
Test should show up under ConfigService
Provide Debug Logs
Attached
KarmaExplorer.log
Please Provide the Following Information
- OS: Ubuntu
- Environment: Local VS Code
- Node Version: 12.22.5
- VSCode Version: 1.63.0
- Karma Version: 6.3
- Frameworks: Angular 13.0.4
Additional Context
Thought it might be the x.x.spec.ts so renamed and made not difference. Created a class in the same directory worked fine.
bibble235 commented
This was caused by using waitForAsync, if you replace it with async it works