Skip to content

Commit

Permalink
Forgot to git add the tests file. Grumble.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesneeringer committed Dec 9, 2016
1 parent ba575e1 commit 9cff4ce
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typed-immutable",
"version": "0.1.0",
"version": "0.1.1",
"description": "Immutable structurally typed data",
"author": "Irakli Gozalishvili <[email protected]> (http:https://jeditoolkit.com)",
"homepage": "https://github.com/typed-immutable/typed-immutable",
Expand Down
69 changes: 69 additions & 0 deletions src/test/immutables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as Immutable from 'immutable'

import test from './test'
import {Record} from '../record'


test('can use Immutable.js objects in records', assert => {
var X = Record({
a: new Immutable.Map({foo: 'bar'}),
})

var x1 = new X()
assert.equals(x1.a.get('foo'), 'bar')
assert.equals(x1.a.get('baz'), undefined)
assert.equals(x1.a.get('baz', 'bacon'), 'bacon')

var x2 = new X({
a: new Immutable.Map({spam: 'eggs'}),
})
assert.equals(x2.a.get('spam'), 'eggs')
assert.equals(x2.a.get('foo'), undefined)
assert.equals(x2.a.get('baz', 'bacon'), 'bacon')

var x3 = new X({
a: {spam: 'eggs'},
})
assert.equals(x3.a instanceof Immutable.Map, true)
assert.equals(x3.a.get('spam'), 'eggs')
assert.equals(x3.a.get('foo'), undefined)
assert.equals(x3.a.get('baz', 'bacon'), 'bacon')
})


test('can use Immutable.js classes in records', assert => {
var X = Record({
a: Immutable.Map,
})

assert.throws(_ => {
var x1 = new X()
})

var x2 = new X({
a: new Immutable.Map({spam: 'eggs'}),
})
assert.equals(x2.a.get('spam'), 'eggs')
assert.equals(x2.a.get('foo'), undefined)
assert.equals(x2.a.get('baz', 'bacon'), 'bacon')

var x3 = new X({
a: {spam: 'eggs'},
})
assert.equals(x3.a instanceof Immutable.Map, true)
assert.equals(x3.a.get('spam'), 'eggs')
assert.equals(x3.a.get('foo'), undefined)
assert.equals(x3.a.get('baz', 'bacon'), 'bacon')
})


test('sets work too', assert => {
var Y = Record({s: new Immutable.Set(['foo'])})
assert.equals(new Y().s.has('foo'), true)
assert.equals(new Y().s.has('bar'), false)

var y2 = new Y({s: ['foo', 'bar', 'baz']})
assert.equals(y2.s.has('baz'), true)

assert.throws(() => { var y3 = new Y({s: null}) })
})

0 comments on commit 9cff4ce

Please sign in to comment.