add measure function test

This commit is contained in:
Dmitry Ivakhnenko
2023-01-26 17:26:30 +03:00
parent 9e1bcd8557
commit 00c3dca3dc

View File

@@ -23,3 +23,33 @@ test("dont_measure_single_grow_shrink_child", () => {
root.freeRecursive();
});
test("dont_fail_with_incomplete_measure_dimensions", () => {
const heightOnlyCallback = getMeasureCounter(Yoga, () => ({ height: 10 }));
const widthOnlyCallback = getMeasureCounter(Yoga, () => ({ width: 10 }));
const emptyCallback = getMeasureCounter(Yoga, () => ({}));
const root = Yoga.Node.create();
root.setWidth(100);
root.setHeight(100);
const node1 = Yoga.Node.create();
const node2 = Yoga.Node.create();
const node3 = Yoga.Node.create();
root.insertChild(node1, root.getChildCount());
root.insertChild(node2, root.getChildCount());
root.insertChild(node3, root.getChildCount());
node1.setMeasureFunc(heightOnlyCallback);
node1.setMeasureFunc(widthOnlyCallback);
node1.setMeasureFunc(emptyCallback);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
expect(heightOnlyCallback.get()).toBe(1);
expect(widthOnlyCallback.get()).toBe(1);
expect(emptyCallback.get()).toBe(1);
root.freeRecursive();
});