Make data module return undefined if key is not found

This commit is contained in:
Juan Cruz Viotti 2014-11-14 14:56:52 -04:00
parent 14bacbc4a4
commit 15620145eb
2 changed files with 12 additions and 2 deletions

View File

@ -20,8 +20,12 @@ constructPath = (key) ->
return result
exports.get = haltIfNoPrefix (key, options, callback) ->
keyPath = constructPath(key)
fs.readFile(keyPath, options, callback)
exports.has key, (hasKey) ->
if not hasKey
return callback?(null)
keyPath = constructPath(key)
fs.readFile(keyPath, options, callback)
exports.set = haltIfNoPrefix (key, value, options, callback) ->
keyPath = constructPath(key)

View File

@ -97,6 +97,12 @@ describe 'Data:', ->
expect(value).to.not.exist
done()
it 'should return undefined if key doesn\'t exists', (done) ->
data.get 'nontexistantkey', encoding: 'utf8', (error, value) ->
expect(error).to.not.exist
expect(value).to.be.undefined
done()
describe '#has()', ->
it 'should return true if a file exists', (done) ->