-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forgot to git add the tests file. Grumble.
- Loading branch information
1 parent
ba575e1
commit 9cff4ce
Showing
2 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) }) | ||
}) |