Reputation: 286
I'm trying to slowly whittle away at errors within a complex module in my application while setting up a new testbed for my application. I'm utilizing the routing factory api from spectator to create my test bed (https://github.com/ngneat/spectator#testing-with-routing)
describe('LoginComponent', () => {
let spectator: SpectatorRouting<LoginComponent>;
let defaultComponentSettings = {
component: LoginComponent,
componentMocks: [SessionQuery],
componentProviders: [
mockProvider(SessionService, {
credentials: { email: '[email protected]' }
})
],
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();
});
});
});
Now things seem to work fine until until I add an anchor with a [routerLink]
directive in my template <a [routerLink]="['/signup']" class="auth-link">Sign up</a>
, this for some reason generates the following error:
● 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)
And I have no idea really how to diagnose this further
Upvotes: 1
Views: 2761
Reputation: 286
Aw, found the answer!
The imports list included a module that itself imported RouterModule
, removing this fixed the error.
Upvotes: 1