Skip to content

Commit 4211203

Browse files
author
huseyinbuyukdere
committed
code review issues are resolved
1 parent b42f196 commit 4211203

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,9 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
837837

838838
const { includedTypes, excludedTypes } = config;
839839
const shouldGenerateMockForType = (typeName: string) => {
840+
if (!typeName) {
841+
return true;
842+
}
840843
if (includedTypes && includedTypes.length > 0) {
841844
return includedTypes.includes(typeName);
842845
}

tests/__snapshots__/typescript-mock-data.spec.ts.snap

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,32 @@ export const aQuery = (overrides?: Partial<Query>): Query => {
15941594
"
15951595
`;
15961596

1597+
exports[`should generate mock data only for included types 1`] = `
1598+
"
1599+
export const anAvatar = (overrides?: Partial<Avatar>): Avatar => {
1600+
return {
1601+
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '1550ff93-cd31-49b4-a3c3-8ef1cb68bdc3',
1602+
url: overrides && overrides.hasOwnProperty('url') ? overrides.url! : 'consectetur',
1603+
};
1604+
};
1605+
1606+
export const aUser = (overrides?: Partial<User>): User => {
1607+
return {
1608+
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'b5756f00-51a6-422a-81a7-dc13ee6a6375',
1609+
creationDate: overrides && overrides.hasOwnProperty('creationDate') ? overrides.creationDate! : '2021-06-27T14:29:24.774Z',
1610+
login: overrides && overrides.hasOwnProperty('login') ? overrides.login! : 'sordeo',
1611+
avatar: overrides && overrides.hasOwnProperty('avatar') ? overrides.avatar! : anAvatar(),
1612+
status: overrides && overrides.hasOwnProperty('status') ? overrides.status! : Status.Online,
1613+
customStatus: overrides && overrides.hasOwnProperty('customStatus') ? overrides.customStatus! : AbcStatus.HasXyzStatus,
1614+
scalarValue: overrides && overrides.hasOwnProperty('scalarValue') ? overrides.scalarValue! : 'arx',
1615+
camelCaseThing: overrides && overrides.hasOwnProperty('camelCaseThing') ? overrides.camelCaseThing! : aCamelCaseThing(),
1616+
unionThing: overrides && overrides.hasOwnProperty('unionThing') ? overrides.unionThing! : anAvatar(),
1617+
prefixedEnum: overrides && overrides.hasOwnProperty('prefixedEnum') ? overrides.prefixedEnum! : PrefixedEnum.PrefixedValue,
1618+
};
1619+
};
1620+
"
1621+
`;
1622+
15971623
exports[`should generate mock data with PascalCase enum values by default 1`] = `
15981624
"
15991625
export const anAvatar = (overrides?: Partial<Avatar>): Avatar => {

tests/typescript-mock-data.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ it('should generate mock data only for included types', async () => {
603603
includedTypes: ['User', 'Avatar'],
604604
});
605605

606+
expect(result).toMatchSnapshot();
606607
expect(result).toBeDefined();
607608
expect(result).toContain('export const aUser');
608609
expect(result).toContain('export const anAvatar');

0 commit comments

Comments
 (0)