Skip to content

Commit

Permalink
Merge pull request #268 from danielbom/fix/force-string-never-works
Browse files Browse the repository at this point in the history
fix: #263 forceString invalid implementation
  • Loading branch information
daluf committed Nov 5, 2021
2 parents 3d6ef83 + 18f8466 commit 1e5c75e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion _src/lib/node_cache.coffee
Expand Up @@ -164,7 +164,7 @@ module.exports = class NodeCache extends EventEmitter
throw _err

# force the data to string
if @options.forceString and not typeof value is "string"
if @options.forceString and typeof value isnt "string"
value = JSON.stringify( value )

# set default ttl if not passed
Expand Down
23 changes: 23 additions & 0 deletions _src/test/mocha_test.coffee
Expand Up @@ -1303,5 +1303,28 @@ describe "`#{pkg.name}@#{pkg.version}` on `node@#{process.version}`", () ->
return
)

describe("#263 - forceString never works", () ->
cache = null
before(() ->
cache = new nodeCache({
forceString: true
})
return
)

it("set the value `null` - this should transform into a string", () ->
cache.set "test", null
should(cache.get("test")).eql("null")
return
)

it("set the value `{ hello: 'World' }` - this should transform into a string", () ->
cache.set "test", { hello: 'World' }
should(cache.get("test")).eql("{\"hello\":\"World\"}")
return
)
return
)

return
return

0 comments on commit 1e5c75e

Please sign in to comment.