Christoph Pojer b84ad2ab0d Updates for haste2 inside of jest
Summary:
I'm working on deploying haste2 with jest. This updates all the files that require changes for this to work and they are backwards compatible with the current version of jest.

* package.json was just outdated. I think haste1's liberal handling with collisions made this a "non-issue"
* env.js didn't properly set up ErrorUtils, also unsure why that isn't a problem in jest right now already?
* some things were mocking things they shouldn't
* Because of the regex that matches against providesModule and System.import, it isn't possible to list module names more than once. We have multiple tests reusing the same providesModule ids and using System.import with modules that only exist virtually within that test. Splitting up the strings makes the regexes work (we do the same kind of splitting on www sometimes if we need to) and using different providesModule names in different test files fixes the problem. I think the BundlesLayoutIntegration-test is going to be deleted, so this doesn't even matter.

public

Reviewed By: voideanvalue

Differential Revision: D2809681

fb-gh-sync-id: 8fe6ed8b5a1be28ba141e9001de143e502693281
2016-01-08 06:52:29 -08:00

111 lines
3.1 KiB
JavaScript

/**
* Copyright (c) 2015, Facebook, Inc. All rights reserved.
*/
'use strict';
jest
.dontMock('NavigationTreeNode')
.dontMock('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']);
});
});