Skip to content

Commit

Permalink
Merge pull request storybookjs#15410 from Marklb/marklb/fix-circular-…
Browse files Browse the repository at this point in the history
…ref-in-module-metadata

Angular: Fix circular reference not being handled in moduleMetadata
  • Loading branch information
shilman authored Jul 2, 2021
2 parents 5096004 + 477eec5 commit 913ae3b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"regenerator-runtime": "^0.13.7",
"sass-loader": "^10.1.0",
"strip-json-comments": "3.1.1",
"telejson": "^5.3.2",
"ts-dedent": "^2.0.0",
"ts-loader": "^8.0.14",
"tsconfig-paths-webpack-plugin": "^3.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { enableProdMode, NgModule, PlatformRef } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { BehaviorSubject, Subject } from 'rxjs';
import { stringify } from 'telejson';
import { ICollection, StoryFnAngularReturnType } from '../types';
import { Parameters } from '../types-6-0';
import { createStorybookModule, getStorybookModuleMetadata } from './StorybookModule';
Expand Down Expand Up @@ -160,7 +161,7 @@ export abstract class AbstractRenderer {

const currentStoryRender = {
storyFnAngular,
moduleMetadataSnapshot: JSON.stringify(moduleMetadata),
moduleMetadataSnapshot: stringify(moduleMetadata),
};

this.previousStoryRenderInfo = currentStoryRender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,29 @@ describe('RendererService', () => {
);
});

it('should handle circular reference in moduleMetadata', async () => {
class Thing {
token: Thing;

constructor() {
this.token = this;
}
}
const token = new Thing();

await rendererService.render({
storyFnAngular: {
template: '🦊',
props: {},
moduleMetadata: { providers: [{ provide: 'foo', useValue: token }] },
},
forced: false,
parameters: {} as any,
});

expect(document.body.getElementsByTagName('storybook-wrapper')[0].innerHTML).toBe('🦊');
});

describe('when forced=true', () => {
beforeEach(async () => {
// Init first render
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { enableProdMode, NgModule, PlatformRef } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { BehaviorSubject, Subject } from 'rxjs';
import { stringify } from 'telejson';
import { ICollection, StoryFnAngularReturnType } from '../types';
import { Parameters } from '../types-6-0';
import { createStorybookModule, getStorybookModuleMetadata } from './StorybookModule';
Expand Down Expand Up @@ -154,7 +155,7 @@ export class RendererService {

this.currentStoryRender = {
storyFnAngular,
moduleMetadataSnapshot: JSON.stringify(moduleMetadata),
moduleMetadataSnapshot: stringify(moduleMetadata),
};

if (
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6170,6 +6170,7 @@ __metadata:
regenerator-runtime: ^0.13.7
sass-loader: ^10.1.0
strip-json-comments: 3.1.1
telejson: ^5.3.2
ts-dedent: ^2.0.0
ts-jest: ^26.4.4
ts-loader: ^8.0.14
Expand Down

0 comments on commit 913ae3b

Please sign in to comment.