1 |
|
2 |
|
3 |
|
4 |
|
5 | var assert = require('should');
|
6 | var parse = require('..');
|
7 |
|
8 | describe('hyper-json-immutable-parse', function() {
|
9 | 'use strict';
|
10 |
|
11 | it('should freeze a parsed object', function() {
|
12 | var obj = JSON.parse('{"foo":{"bar": "baz"},"test":[]}', parse);
|
13 | assert.throws(function() {
|
14 | obj.foo = 1;
|
15 | });
|
16 | assert.throws(function() {
|
17 | obj.other = true;
|
18 | });
|
19 | assert.throws(function() {
|
20 | obj.test.push(1);
|
21 | });
|
22 | });
|
23 |
|
24 | it('should resolve local JSON pointers', function() {
|
25 | var base = 'http://example.com';
|
26 | var obj = JSON.parse('{"href": "/", "user": {"name": {"href": "#/name"}}, "name": "Joe"}', parse(base));
|
27 | assert.equal(obj.user.name.href, base + '#/name');
|
28 | });
|
29 |
|
30 | it('should create a __hash for object comparison', function() {
|
31 | var str = '{"href": "other", "foo": {"bar": "baz"}}';
|
32 | assert.equal(JSON.parse(str, parse).__hash, JSON.parse(str, parse).__hash);
|
33 | });
|
34 | });
|