From 107fc72dab6b0189878b7023c08bd9bfad10c160 Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Mon, 22 Aug 2016 13:05:34 -0700 Subject: [PATCH] Fixes #9294 Differential Revision: D3752878 fbshipit-source-id: f248082effde9133dd6a9edf8a2f2cfc05279eab --- .../android/makeStringsPatch.spec.js | 20 +++++++++++++++++++ .../link/android/patches/makeStringsPatch.js | 17 ++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 local-cli/link/__tests__/android/makeStringsPatch.spec.js 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, }; };