Skip to content

Commit 1e5c75e

Browse files
authored
Merge pull request #268 from danielbom/fix/force-string-never-works
fix: #263 forceString invalid implementation
2 parents 3d6ef83 + 18f8466 commit 1e5c75e

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

_src/lib/node_cache.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ module.exports = class NodeCache extends EventEmitter
164164
throw _err
165165

166166
# force the data to string
167-
if @options.forceString and not typeof value is "string"
167+
if @options.forceString and typeof value isnt "string"
168168
value = JSON.stringify( value )
169169

170170
# set default ttl if not passed

_src/test/mocha_test.coffee

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,5 +1303,28 @@ describe "`#{pkg.name}@#{pkg.version}` on `node@#{process.version}`", () ->
13031303
return
13041304
)
13051305

1306+
describe("#263 - forceString never works", () ->
1307+
cache = null
1308+
before(() ->
1309+
cache = new nodeCache({
1310+
forceString: true
1311+
})
1312+
return
1313+
)
1314+
1315+
it("set the value `null` - this should transform into a string", () ->
1316+
cache.set "test", null
1317+
should(cache.get("test")).eql("null")
1318+
return
1319+
)
1320+
1321+
it("set the value `{ hello: 'World' }` - this should transform into a string", () ->
1322+
cache.set "test", { hello: 'World' }
1323+
should(cache.get("test")).eql("{\"hello\":\"World\"}")
1324+
return
1325+
)
1326+
return
1327+
)
1328+
13061329
return
13071330
return

0 commit comments

Comments
 (0)