diff --git a/local-cli/link/__tests__/android/makeStringsPatch.spec.js b/local-cli/link/__tests__/android/makeStringsPatch.spec.js new file mode 100644 index 0000000000..b954e263a2 --- /dev/null +++ b/local-cli/link/__tests__/android/makeStringsPatch.spec.js @@ -0,0 +1,20 @@ +'use strict'; + +jest.autoMockOff(); + +const makeStringsPatch = require('../../android/patches/makeStringsPatch'); + +describe('makeStringsPatch', () => { + it('should export a patch with element', () => { + const params = { + keyA: 'valueA', + }; + + expect(makeStringsPatch(params, 'module').patch) + .toContain('valueA'); + }); + + it('should export an empty patch if no params given', () => { + expect(makeStringsPatch({}, 'module').patch).toBe(''); + }); +}); diff --git a/local-cli/link/android/patches/makeStringsPatch.js b/local-cli/link/android/patches/makeStringsPatch.js index b71bc6c00b..b905963596 100644 --- a/local-cli/link/android/patches/makeStringsPatch.js +++ b/local-cli/link/android/patches/makeStringsPatch.js @@ -1,14 +1,19 @@ const toCamelCase = require('lodash').camelCase; module.exports = function makeStringsPatch(params, prefix) { - const patch = Object.keys(params).map(param => { - const name = toCamelCase(prefix) + '_' + param; - return ' ' + - `${params[param]}`; - }).join('\n') + '\n'; + const values = Object.keys(params) + .map(param => { + const name = toCamelCase(prefix) + '_' + param; + return ' ' + + `${params[param]}`; + }); + + const patch = values.length > 0 + ? values.join('\n') + '\n' + : ''; return { pattern: '\n', - patch: patch, + patch, }; };