首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角6业力测试API问题

角6业力测试API问题
EN

Stack Overflow用户
提问于 2018-08-15 08:14:39
回答 1查看 255关注 0票数 0

我刚开始进行单元测试。我已经创建了一个角6应用程序,并希望进行单元测试。在运行ng test之后,我遇到了一些错误。

通知页正在调用在NotificationService.getNotifications()中定义的服务notification.service.ts

通知组件测试文件:

代码语言:javascript
复制
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientModule } from '@angular/common/http';
import { NotificationsPageComponent } from './notifications-page.component';
import { RouterTestingModule } from "@angular/router/testing";

import { AuthService } from '../../shared/auth/auth.service';

describe('NotificationsPageComponent', () => {
  let component: NotificationsPageComponent;
  let fixture: ComponentFixture<NotificationsPageComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      providers: [AuthService],
      declarations: [ NotificationsPageComponent ],
      imports: [HttpClientModule, RouterTestingModule]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(NotificationsPageComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});

notification.service.ts

代码语言:javascript
复制
import { AppConfigService } from '../services/app-config.service';
import { AuthService } from '../shared/auth/auth.service';
....
export class NotificationService {
    ....
    getNotifications() {
        return this.http.get(this.appConfig.config.api_link + '/notes?show_on_dashboard=true', { headers: this.authService.header() })
        .pipe(map(res => JSON.stringify(res)));
    }
}

这个api_link来自app-config.service.ts

app-config.service.ts

代码语言:javascript
复制
import { environment } from 'environments/environment';
export class AppConfigService {
    private appConfig;
    loadAppConfig() {
        this.http.get('./environments/env_settings.json').subscribe((data) => {
            this.appConfig = data;
            console.log('Environment variables loaded from env_settings.json');
            console.log(this.appConfig);
        },
        (err) => {
            console.warn("Error loading env_settings.json, using envrionment file instead");
            this.appConfig = environment;
        });
    }

    get config() {
        return this.appConfig;
    }
}

我在Karma控制台中得到了6个错误,它们都是相同的TypeError:无法读取未定义的的属性'api_link‘

任何帮助都将不胜感激。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2019-04-03 13:42:41

您没有在测试规范中提供AppConfigService。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51855165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档