Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular ngrx/store-测试,抛出类型错误:无法读取未定义的属性“pipe”_Angular_Typescript_Ngrx_Angular8_Angular Unit Test - Fatal编程技术网

Angular ngrx/store-测试,抛出类型错误:无法读取未定义的属性“pipe”

Angular ngrx/store-测试,抛出类型错误:无法读取未定义的属性“pipe”,angular,typescript,ngrx,angular8,angular-unit-test,Angular,Typescript,Ngrx,Angular8,Angular Unit Test,这是我的ts文件: this.store.pipe(select(subscribe.getRegCategories)).pipe(takeUntil(this.ngUnsubscribe)).subscribe(data => { if (data && data.length) { this.allRegCategories = data; } }); 当我进行测试时,得

这是我的ts文件:

this.store.pipe(select(subscribe.getRegCategories)).pipe(takeUntil(this.ngUnsubscribe)).subscribe(data => {
            if (data && data.length) {
                this.allRegCategories = data;
            }
        });
当我进行测试时,得到的错误如下:

this.store.pipe(select(subscribe.getRegCategories)).pipe(takeUntil(this.ngUnsubscribe)).subscribe(data => {

TypeError: Cannot read property 'pipe' of undefined
这里如何提供管道?解决这个问题的正确方法是什么

这是我的测试规范文件:

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Store, select } from '@ngrx/store';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpClientModule } from '@angular/common/http';
import { ShellViewProgMgmtComponent } from './shell-view-prog-mgmt.component';
import { ViewProgMgmtComponent } from './../../components/view-prog-mgmt/view-prog-mgmt.component';
import * as actions from './../../state/actions/setup-config.actions';

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

    beforeEach(async(() => {
        TestBed.configureTestingModule({
            declarations: [ShellViewProgMgmtComponent, ViewProgMgmtComponent],
            imports: [HttpClientModule, RouterTestingModule],
            providers: [
            {
                provide: Store,
                useValue: {
                    dispatch: jest.fn(),
                    pipe: jest.fn()
                }
            }
            ]
        })
        .compileComponents();
    }));

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

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

    describe('ngOnInit()', () => {

        it('should dispatch an event resetEditPage action in ngOnit lifecycle', () => {

            const store = TestBed.get(Store);
            const action = actions.resetEditPage();
            const spy = jest.spyOn(store, 'dispatch');

            fixture.detectChanges();
            expect(spy).toHaveBeenCalledWith(action);

        });

    });
});

请不要嘲笑你自己的商店

取而代之的是使用MockStore和/或mock选择器,因为这会让你的生活更轻松。 如果这是您想要的,您可以查看一下实现以了解如何创建模拟存储


您是否创建了存储类型的实例?就像我们在角构造器中做的那样@timdeschryer,谢谢你的建议!!是的,我执行了文档。但当此用户遇到问题时:https://stackoverflow.com/questions/58172016/typeerror-actual-subscribe-is-not-a-function -你能帮我整理一下吗?我不想像我一样提出新的问题