diff --git a/.gitignore b/.gitignore index 2db0d4ded..6708a330d 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ npm-debug.log* lerna-debug.log* /**/*.tgz /.idea/ +.vscode diff --git a/library/src/helpers/__tests__/__snapshots__/schema.test.ts.snap b/library/src/helpers/__tests__/__snapshots__/schema.test.ts.snap new file mode 100644 index 000000000..2c902a75f --- /dev/null +++ b/library/src/helpers/__tests__/__snapshots__/schema.test.ts.snap @@ -0,0 +1,13 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`SchemaHelpers .applicatorSchemaName should not render title because title is null 1`] = `"first case:"`; + +exports[`SchemaHelpers .applicatorSchemaName should not render title because title is null 2`] = `"other cases:"`; + +exports[`SchemaHelpers .applicatorSchemaName should not render title because title is undefined 1`] = `"first case:"`; + +exports[`SchemaHelpers .applicatorSchemaName should not render title because title is undefined 2`] = `"other cases:"`; + +exports[`SchemaHelpers .applicatorSchemaName should render title 1`] = `"first case title example:"`; + +exports[`SchemaHelpers .applicatorSchemaName should render title 2`] = `"other cases title example:"`; diff --git a/library/src/helpers/__tests__/schema.test.ts b/library/src/helpers/__tests__/schema.test.ts index 5515aa5e7..ebe27c1b8 100644 --- a/library/src/helpers/__tests__/schema.test.ts +++ b/library/src/helpers/__tests__/schema.test.ts @@ -869,4 +869,60 @@ describe('SchemaHelpers', () => { expect(result).toEqual(expected); }); }); + + describe('.applicatorSchemaName', () => { + const FIRST_CASE = 'first case'; + const OTHER_CASES = 'other cases'; + + test('should not render title because title is null', () => { + expect( + SchemaHelpers.applicatorSchemaName( + 0, + FIRST_CASE, + OTHER_CASES, + null as never, + ), + ).toMatchSnapshot(); + + expect( + SchemaHelpers.applicatorSchemaName( + 1, + FIRST_CASE, + OTHER_CASES, + null as never, + ), + ).toMatchSnapshot(); + }); + + test('should not render title because title is undefined', () => { + expect( + SchemaHelpers.applicatorSchemaName( + 0, + FIRST_CASE, + OTHER_CASES, + undefined, + ), + ).toMatchSnapshot(); + + expect( + SchemaHelpers.applicatorSchemaName( + 1, + FIRST_CASE, + OTHER_CASES, + undefined, + ), + ).toMatchSnapshot(); + }); + + test('should render title', () => { + const TITLE = 'title example'; + expect( + SchemaHelpers.applicatorSchemaName(0, FIRST_CASE, OTHER_CASES, TITLE), + ).toMatchSnapshot(); + + expect( + SchemaHelpers.applicatorSchemaName(1, FIRST_CASE, OTHER_CASES, TITLE), + ).toMatchSnapshot(); + }); + }); }); diff --git a/library/src/helpers/schema.ts b/library/src/helpers/schema.ts index d0f08f7b1..c84c4e395 100644 --- a/library/src/helpers/schema.ts +++ b/library/src/helpers/schema.ts @@ -107,7 +107,7 @@ export class SchemaHelpers { otherCases: string, title?: string, ) { - const suffix = (title !== null && ` ${title}:`) || `:`; + const suffix = title ? ` ${title}:` : ':'; if (idx === 0) { return `${firstCase}${suffix}`; } else {