首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >` `TypeError:为使用routerLink、Spectator和Jest的角度组件编写测试时,将循环结构转换为JSON`错误

` `TypeError:为使用routerLink、Spectator和Jest的角度组件编写测试时,将循环结构转换为JSON`错误
EN

Stack Overflow用户
提问于 2021-11-01 00:25:29
回答 1查看 195关注 0票数 1

在为我的应用程序设置新的试验台时,我正在尝试慢慢减少应用程序中复杂模块中的错误。我正在利用来自旁观者的路由工厂api来创建我的测试床(https://github.com/ngneat/spectator#testing-with-routing)。

代码语言:javascript
复制
describe('LoginComponent', () => {
  let spectator: SpectatorRouting<LoginComponent>;
  let defaultComponentSettings = {
    component: LoginComponent,
    componentMocks: [SessionQuery],
    componentProviders: [
      mockProvider(SessionService, {
        credentials: { email: 'name@example.com' }
      })
    ],
    imports: [...imports, HttpClientTestingModule],
    url: [new UrlSegment('/login', {})]
  };

  let createTargetRedirectUrlComponent = createRoutingFactory({
    ...defaultComponentSettings,
    queryParams: {
      redirectUrl: 'http://any/'
    }
  });

  describe('with target redirectUrl', () => {
    beforeEach(() => {
      spectator = createTargetRedirectUrlComponent();
      spectator.component.mfa_token_view$ = of(false);
      spectator.detectChanges();
    });

    it('should have a sign up link', () => {
      console.log('do we have a form yet', spectator.query('form'));
      expect(spectator.query(byText('Sign up'))).toBeTruthy();
    });
  });
});

现在,直到我在模板<a [routerLink]="['/signup']" class="auth-link">Sign up</a>中添加一个带有[routerLink]指令的锚点之前,一切似乎都运行得很好,由于某种原因,这会生成以下错误:

代码语言:javascript
复制
  ● Test suite failed to run

    TypeError: Converting circular structure to JSON
        --> starting at object with constructor 'Object'
        |     property 'element' -> object with constructor 'Object'
        |     property 'publicProviders' -> object with constructor 'Object'
        |     property 'RouterLink_109' -> object with constructor 'Object'
        --- property 'parent' closes the circle
        at stringify (<anonymous>)

      at messageParent (node_modules/jest-runner/node_modules/jest-worker/build/workers/messageParent.js:34:19)

我真的不知道如何进一步诊断

EN

回答 1

Stack Overflow用户

发布于 2021-11-01 00:31:06

啊,找到答案了!

导入列表包含一个模块,该模块本身导入了RouterModule,删除该模块修复了错误。

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

https://stackoverflow.com/questions/69791595

复制
相关文章

相似问题

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