@basd/nested
Version:
Allows you to create deeply nested object structures, while also enabling you to traverse them efficiently.
29 lines (21 loc) • 906 B
JavaScript
const Nested = require('../lib/nested')
describe('Nested class', () => {
it('should set parent and path in constructor', () => {
const parent = new Nested({ path: ['root'] })
const child = new Nested({ parent, path: ['root', 'child'] })
expect(child.parent).to.equal(parent)
expect(child.path).to.eql(['root', 'child'])
})
it('should return the root node', () => {
const root = new Nested({ path: ['root'] })
const child = new Nested({ parent: root, path: ['root', 'child'] })
const grandChild = new Nested({ parent: child, path: ['root', 'child', 'grandChild'] })
expect(grandChild.root).to.equal(root)
})
it('should create a sub-node with correct properties', () => {
const root = new Nested({ path: ['root'] })
const subNode = root.sub('child')
expect(subNode.parent).to.equal(root)
expect(subNode.path).to.eql(['root', 'child'])
})
})