Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.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/效果的6个jasmine测试用例_Angular_Jasmine_Karma Jasmine_Ngrx Effects_Switchmap - Fatal编程技术网

Angular ngrx/效果的6个jasmine测试用例

Angular ngrx/效果的6个jasmine测试用例,angular,jasmine,karma-jasmine,ngrx-effects,switchmap,Angular,Jasmine,Karma Jasmine,Ngrx Effects,Switchmap,我正试图为效果编写测试用例。有谁能帮我测试一下它里面的switchMap函数吗。提前谢谢。这是我的功能 loadMovies$ = createEffect(() => this.actions$.pipe( ofType('[Login Page] Login'), switchMap(() => this.exampleService.getAll() .pipe( map(movies => ({ type: '[Movies

我正试图为效果编写测试用例。有谁能帮我测试一下它里面的switchMap函数吗。提前谢谢。这是我的功能

loadMovies$ = createEffect(() => this.actions$.pipe(
    ofType('[Login Page] Login'),
    switchMap(() => this.exampleService.getAll()
      .pipe(
        map(movies => ({ type: '[Movies API] Movies Loaded Success', payload: movies })),
        catchError(() => EMPTY)
      ))
    )
  );
还有我的规格文件

it('should return an AddUserSuccess action, with the user, on success', () => {

   actions$ = of({ type: '[Customers Page] Get Customers' });  

    service.getAll();
     effects.loadMovies$.subscribe(action => {
        expect(action).toEqual({
            type: '[Customers API] Get Customers Success',
            payload: [],
        });
    });
  });

您正在测试switchmap函数吗?通常我相信开发它的人知道他们在做什么。相反,我测试调用的函数是否返回预期结果。你有错误吗?发生了什么事?我没有错误。我正在尝试以预期的回报测试函数。但是有些家庭我的函数没有覆盖switchMap代码。啊,我明白了,所以你在代码覆盖方面有问题。您需要创建一个测试夹具,其中的case get触发switchmap,我想它类似于
actions$.next(newactions.LoadMovies())或类似的东西。你订阅的是可观测的,但你没有发射,所以预期永远不会被触发,因为什么都没有发生(我认为)@rmjoia它起作用了。非常感谢。