首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未定义的TypeError:无法读取属性“团队”的未定义抛出-业力

未定义的TypeError:无法读取属性“团队”的未定义抛出-业力
EN

Stack Overflow用户
提问于 2019-05-29 00:09:25
回答 1查看 2.7K关注 0票数 3

我在运行ng test时遇到了这个问题。它编译得很好,ng build --prod运行得很好。我甚至没有看到那些变量的名字,只有可观测的,但有一个$ infront的变量。

问题更新

“@type/jasmine”:"2.8.9“、”@type/jasminewd2 2“:"~2.0.3”、“@类型/节点”:"~8.9.4“、"codelyzer":"~4.2.1”、“茉莉花-核心”:"~2.99.1“、”茉莉花-spec-记者“:"~4.2.1”、“业力”:"~1.7.1",“业力-铬发射器”:"~2.2.0“、”业力-报道-伊斯坦布尔-记者“:”2.0.0“、”业力-茉莉花“:”1.1.1“、”业力-茉莉花-html-记者“:"^0.2.2”、“量角器”:"^5.4.2“、”ts-节点“:"~5.0.1","tslint":"~5.9.1",“打字本”:"~2.7.2“

当卡玛打开的时候,我只看到了

我的命令行

父测试文件

代码语言:javascript
复制
describe('MembersComponent', () => {
  let component: MembersComponent;
  let fixture: ComponentFixture<MembersComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [
        ReactiveFormsModule,
        HttpClientModule,
        RouterTestingModule,
        StoreModule.forRoot({})
      ],
      declarations: [MembersComponent, ModalComponent],
      providers: [{ provide: Store, useClass: StoreStub }]
    }).compileComponents();
  }));

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

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

子测试文件

代码语言:javascript
复制
describe('ModalComponent', () => {
  let component: ModalComponent;
  let fixture: ComponentFixture<ModalComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ModalComponent],
      imports: [FormsModule, ReactiveFormsModule, StoreModule.forRoot({})],
      providers: [Store]
    }).compileComponents();
  }));

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

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

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-29 03:18:25

如果您甚至不想测试store,请尝试如下:

代码语言:javascript
复制
import { of } from 'rxjs';

class StoreStub {
    select(val: any) {
        if (val === 'whatever action you have defined for RacingSelectors.selectMembers') {
            return of<Member[]>([
                {}, // create dummy member objects
            ]);
        } else if (val === 'whatever action you have defined for RacingSelectors.selectTeams') {
            return of<Team[]>([
                { firstName: '' },
                { lastName: '' },
                { jobTitle: '' },
                { team: '' },
                { status: '' }, // create dummy member objects
            ]);
        }
    }
    dispatch() {}
}

spec文件中:

代码语言:javascript
复制
    TestBed.configureTestingModule({
      imports: [
        ReactiveFormsModule,
        HttpClientModule,
        RouterTestingModule,
        StoreModule.forRoot({})
      ],
      declarations: [MembersComponent, ModalComponent],
      providers: [{ provide: Store, useClass: StoreStub}]
    }).compileComponents();
  }));

  it('should create', () => { 
        component.ngOnInit(); 
       expect(component).toBeTruthy(); 
   }); 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56351507

复制
相关文章

相似问题

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