Skip to content

Commit

Permalink
TST: Add test for circular json serialization / deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
nopnop committed Jul 28, 2016
1 parent 2be1c24 commit 07d2ddd
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion test/specs/cache.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe( 'flat-cache', function () {
'use strict';
var expect = require( 'chai' ).expect;
var readJSON = require( 'read-json-sync' );
var readJSON = require( '../../utils.js' ).readJSON;
var path = require( 'path' );
var del = require( 'del' ).sync;
var fs = require( 'fs' );
Expand Down Expand Up @@ -222,4 +222,20 @@ describe( 'flat-cache', function () {
} );
} );

it( 'should serialize and deserialize properly circular reference', function () {
var cache = flatCache.load( 'someId' );
var data = {
foo: 'foo',
bar: 'bar'
};

data.circular = data

cache.setKey( 'some-key', data );
expect( cache.getKey( 'some-key' ) ).to.deep.equal( data );

cache.save();
expect( readJSON( path.resolve( __dirname, '../../.cache/someId' ) )[ 'some-key' ] ).to.deep.equal( data );
} );

} );

0 comments on commit 07d2ddd

Please sign in to comment.