Created
January 4, 2016 21:20
-
-
Save famousgarkin/b826b1ecefb7dcecf305 to your computer and use it in GitHub Desktop.
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
var Immutable = require('immutable'); | |
describe('Immutable', function () { | |
it('can create nested groups', function () { | |
var items = [ | |
{key1: 'a', key2: 'A'}, | |
{key1: 'a', key2: 'A'}, | |
{key1: 'a', key2: 'B'}, | |
{key1: 'b', key2: 'A'}, | |
{key1: 'b', key2: 'B'} | |
]; | |
var result = Immutable.List(items) | |
.groupBy(function (item) { | |
return item.key1; | |
}) | |
.map(function (items) { | |
return items.groupBy(function (item) { | |
return item.key2; | |
}); | |
}) | |
.toJS(); | |
expect(result.a.A).toContain(items[0]); | |
expect(result.a.A).toContain(items[1]); | |
expect(result.a.B).toContain(items[2]); | |
expect(result.b.A).toContain(items[3]); | |
expect(result.b.B).toContain(items[4]); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment