lucono/karma-test-explorer

Unmapped Tests for Config Initializer

bibble235 opened this issue · 1 comments

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

  1. Create an Angular project v13.0.4
  2. Create an initializer (config.service.initializer.ts)
  3. 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

Screenshots
Attached
bug_karma

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.

This was caused by using waitForAsync, if you replace it with async it works