Skip to content
Merged
Prev Previous commit
Next Next commit
Update with the new tests
  • Loading branch information
elicwhite committed Apr 9, 2019
commit cd087b05391171f670cac05ccdf160ea96579c2b
53 changes: 50 additions & 3 deletions packages/react-native-renderer/src/__mocks__/FabricUIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,56 @@ const RCTFabricUIManager = {

registerEventHandler: jest.fn(function registerEventHandler(callback) {}),

measure: jest.fn(),
measureLayout: jest.fn(),
measureInWindow: jest.fn(),
measure: jest.fn(function measure(node, callback) {
invariant(
typeof node === 'object',
'Expected node to be an object, was passed "%s"',
typeof node,
);
invariant(
typeof node.viewName === 'string',
'Expected node to be a host node.',
);
callback(10, 10, 100, 100, 0, 0);
}),
measureInWindow: jest.fn(function measureInWindow(node, callback) {
invariant(
typeof node === 'object',
'Expected node to be an object, was passed "%s"',
typeof node,
);
invariant(
typeof node.viewName === 'string',
'Expected node to be a host node.',
);
callback(10, 10, 100, 100);
}),
measureLayout: jest.fn(function measureLayout(
node,
relativeNode,
fail,
success,
) {
invariant(
typeof node === 'object',
'Expected node to be an object, was passed "%s"',
typeof node,
);
invariant(
typeof node.viewName === 'string',
'Expected node to be a host node.',
);
invariant(
typeof relativeNode === 'object',
'Expected relative node to be an object, was passed "%s"',
typeof relativeNode,
);
invariant(
typeof relativeNode.viewName === 'string',
'Expected relative node to be a host node.',
);
success(1, 1, 100, 100);
}),
};

module.exports = RCTFabricUIManager;
Original file line number Diff line number Diff line change
Expand Up @@ -335,20 +335,11 @@ describe('ReactFabric', () => {
);

expect(FabricUIManager.measure).not.toBeCalled();

const successCallback = jest.fn();
viewRef.measure(successCallback);

expect(FabricUIManager.measure).toHaveBeenCalledTimes(1);
expect(FabricUIManager.measure).toHaveBeenCalledWith(
expect.any(Object),
expect.any(Function),
);

const args = FabricUIManager.measure.mock.calls[0];
expect(successCallback).not.toBeCalled();
args[1]('success');
expect(successCallback).toBeCalledWith('success');
expect(successCallback).toHaveBeenCalledTimes(1);
expect(successCallback).toHaveBeenCalledWith(10, 10, 100, 100, 0, 0);
});
});

Expand Down Expand Up @@ -385,20 +376,11 @@ describe('ReactFabric', () => {
);

expect(FabricUIManager.measureInWindow).not.toBeCalled();

const successCallback = jest.fn();
viewRef.measureInWindow(successCallback);

expect(FabricUIManager.measureInWindow).toHaveBeenCalledTimes(1);
expect(FabricUIManager.measureInWindow).toHaveBeenCalledWith(
expect.any(Object),
expect.any(Function),
);

const args = FabricUIManager.measureInWindow.mock.calls[0];
expect(successCallback).not.toBeCalled();
args[1]('success');
expect(successCallback).toBeCalledWith('success');
expect(successCallback).toHaveBeenCalledTimes(1);
expect(successCallback).toHaveBeenCalledWith(10, 10, 100, 100);
});
});

Expand All @@ -409,7 +391,7 @@ describe('ReactFabric', () => {
}));

[View].forEach(Component => {
FabricUIManager.measureLayout.mockReset();
FabricUIManager.measureLayout.mockClear();

let viewRef;
let otherRef;
Expand All @@ -431,29 +413,12 @@ describe('ReactFabric', () => {
);

expect(FabricUIManager.measureLayout).not.toBeCalled();

const successCallback = jest.fn();
const failureCallback = jest.fn();
viewRef.measureLayout(otherRef, successCallback, failureCallback);

expect(FabricUIManager.measureLayout).toHaveBeenCalledTimes(1);
expect(FabricUIManager.measureLayout).toHaveBeenCalledWith(
expect.any(Object),
expect.any(Object),
expect.any(Function),
expect.any(Function),
);

const args = FabricUIManager.measureLayout.mock.calls[0];
expect(args[0]).not.toEqual(args[1]);
expect(successCallback).not.toBeCalled();
expect(failureCallback).not.toBeCalled();
args[2]('fail');
expect(failureCallback).toBeCalledWith('fail');

expect(successCallback).not.toBeCalled();
args[3]('success');
expect(successCallback).toBeCalledWith('success');
expect(successCallback).toHaveBeenCalledTimes(1);
expect(successCallback).toHaveBeenCalledWith(1, 1, 100, 100);
});
});

Expand Down