diff --git a/atom/browser/api/atom_api_system_preferences_mac.mm b/atom/browser/api/atom_api_system_preferences_mac.mm index 70997ed01298..465decf3164a 100644 --- a/atom/browser/api/atom_api_system_preferences_mac.mm +++ b/atom/browser/api/atom_api_system_preferences_mac.mm @@ -150,7 +150,6 @@ void SystemPreferences::RegisterDefaults(mate::Arguments* args) { if(!args->GetNext(&value)) { args->ThrowError("Invalid userDefault data provided"); } else { - args->GetNext(&value); @try { NSDictionary* dict = DictionaryValueToNSDictionary(value); [[NSUserDefaults standardUserDefaults] registerDefaults:dict]; diff --git a/spec/api-system-preferences-spec.js b/spec/api-system-preferences-spec.js index 15d50d67ac75..50becf1604e7 100644 --- a/spec/api-system-preferences-spec.js +++ b/spec/api-system-preferences-spec.js @@ -41,45 +41,35 @@ describe('systemPreferences module', () => { }) it('registers defaults', () => { - // to pass into registerDefaults - const defaultsDict = { - 'one': 'ONE', - 'two': 2, - 'three': [1, 2, 3] - } - - // to test type const defaultsMap = [ { key: 'one', type: 'string', value: 'ONE' }, { key: 'two', value: 2, type: 'integer' }, { key: 'three', value: [1, 2, 3], type: 'array' } ] + const defaultsDict = {} + defaultsMap.forEach(row => { defaultsDict[row.key] = row.value }) + systemPreferences.registerDefaults(defaultsDict) - for (const def of defaultsMap) { - const [key, expectedValue, type] = [def.key, def.value, def.type] + for (const userDefault of defaultsMap) { + const { key, value: expectedValue, type } = userDefault const actualValue = systemPreferences.getUserDefault(key, type) assert.deepEqual(actualValue, expectedValue) } }) it('throws when bad defaults are passed', () => { - const badDefaults1 = { 'one': null } // catches null values - const badDefaults2 = 1 // argument must be a dictionary - const badDefaults3 = null // argument can't be null - - assert.throws(() => { - systemPreferences.registerDefaults(badDefaults1) - }, 'Invalid userDefault data provided') - - assert.throws(() => { - systemPreferences.registerDefaults(badDefaults2) - }, 'Invalid userDefault data provided') - - assert.throws(() => { - systemPreferences.registerDefaults(badDefaults3) - }, 'Invalid userDefault data provided') + for (const badDefaults of [ + { 'one': null }, // catches null values + 1, // argument must be a dictionary + null, // argument can't be null + new Date() // shouldn't be able to pass date object + ]) { + assert.throws(() => { + systemPreferences.registerDefaults(badDefaults) + }, 'Invalid userDefault data provided') + } }) })