David Aurelio ad8a335864 Remove knowledge of fbjs from the packager
Summary:Follow-up to https://github.com/facebook/react-native/pull/5084

This…
- changes all requires within RN to `require('fbjs/lib/…')`
- updates `.flowconfig`
- updates `packager/blacklist.js`
- adapts tests
- removes things from `Libraries/vendor/{core,emitter}` that are also in fbjs
- removes knowledge of `fbjs` from the packager

Closes https://github.com/facebook/react-native/pull/5084

Reviewed By: bestander

Differential Revision: D2926835

fb-gh-sync-id: 2095e22b2f38e032599d1f2601722b3560e8b6e9
shipit-source-id: 2095e22b2f38e032599d1f2601722b3560e8b6e9
2016-03-02 04:28:38 -08:00

111 lines
3.1 KiB
JavaScript

/**
* Copyright (c) 2015, Facebook, Inc. All rights reserved.
*/
'use strict';
jest
.dontMock('NavigationTreeNode')
.dontMock('fbjs/lib/invariant')
.dontMock('immutable');
var NavigationTreeNode = require('NavigationTreeNode');
describe('NavigationTreeNode-test', () => {
it('should be empty', () => {
var node = new NavigationTreeNode();
expect(node.getValue()).toEqual(undefined);
expect(node.getParent()).toEqual(null);
expect(node.getChildrenCount()).toEqual(0);
expect(node.getChildAt(0)).toEqual(null);
});
it('should contain value', () => {
var node = new NavigationTreeNode(123);
expect(node.getValue()).toEqual(123);
});
it('should appendChild', () => {
var papa = new NavigationTreeNode('hedger');
var baby = new NavigationTreeNode('hedger jr');
papa.appendChild(baby);
expect(papa.getChildAt(0)).toEqual(baby);
expect(papa.getChildrenCount()).toEqual(1);
expect(baby.getParent()).toEqual(papa);
});
it('should removeChild', () => {
var papa = new NavigationTreeNode('Eddard Stark');
var baby = new NavigationTreeNode('Robb Stark');
papa.appendChild(baby);
papa.removeChild(baby);
expect(papa.getChildAt(0)).toEqual(null);
expect(papa.getChildrenCount()).toEqual(0);
expect(baby.getParent()).toEqual(null);
});
it('should not remove non-child', () => {
var papa = new NavigationTreeNode('dog');
var baby = new NavigationTreeNode('cat');
expect(papa.removeChild.bind(papa, baby)).toThrow();
});
it('should find child', () => {
var papa = new NavigationTreeNode('Eddard Stark');
var baby = new NavigationTreeNode('Robb Stark');
papa.appendChild(baby);
expect(papa.indexOf(baby)).toEqual(0);
papa.removeChild(baby);
expect(papa.indexOf(baby)).toEqual(-1);
});
it('should traverse each child', () => {
var parent = new NavigationTreeNode();
parent.appendChild(new NavigationTreeNode('a'));
parent.appendChild(new NavigationTreeNode('b'));
parent.appendChild(new NavigationTreeNode('c'));
var result = [];
parent.forEach((child, index) => {
result[index] = child.getValue();
});
expect(result).toEqual(['a', 'b', 'c']);
});
it('should map children', () => {
var parent = new NavigationTreeNode();
parent.appendChild(new NavigationTreeNode('a'));
parent.appendChild(new NavigationTreeNode('b'));
parent.appendChild(new NavigationTreeNode('c'));
var result = parent.map((child, index) => {
return child.getValue();
});
expect(result).toEqual(['a', 'b', 'c']);
});
it('should traverse some children', () => {
var parent = new NavigationTreeNode();
parent.appendChild(new NavigationTreeNode('a'));
parent.appendChild(new NavigationTreeNode('b'));
parent.appendChild(new NavigationTreeNode('c'));
var result = [];
var value = parent.some((child, index) => {
if (index > 1) {
return true;
} else {
result[index] = child.getValue();
}
});
expect(value).toEqual(true);
expect(result).toEqual(['a', 'b']);
});
});