Convert manually authored tests to TypeScript
Summary: Converts the manually authored tests against the JavaScript bindings to TypeScript. This should make authoring UTs a bit more pleasent, but more importantly lets us run typechecking on sample usage of all of the various APIs. Reviewed By: yungsters Differential Revision: D45570416 fbshipit-source-id: 44586b4d31fbeae406b388ed336a8305c788b5dd
This commit is contained in:
committed by
Facebook GitHub Bot
parent
172bd0a88e
commit
0cb4a49d38
@@ -5,6 +5,8 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import { Yoga } from "./tools/globals";
|
||||
|
||||
test("align_baseline_parent_using_child_in_column_as_reference", () => {
|
||||
const config = Yoga.Config.create();
|
||||
let root;
|
||||
@@ -41,7 +43,7 @@ test("align_baseline_parent_using_child_in_column_as_reference", () => {
|
||||
root_child1_child1.setIsReferenceBaseline(true);
|
||||
root_child1.insertChild(root_child1_child1, 1);
|
||||
|
||||
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
|
||||
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
|
||||
|
||||
expect(root_child0.getComputedLeft()).toBe(0);
|
||||
expect(root_child0.getComputedTop()).toBe(100);
|
||||
@@ -99,7 +101,7 @@ test("align_baseline_parent_using_child_in_row_as_reference", () => {
|
||||
root_child1_child1.setIsReferenceBaseline(true);
|
||||
root_child1.insertChild(root_child1_child1, 1);
|
||||
|
||||
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
|
||||
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
|
||||
|
||||
expect(root_child0.getComputedLeft()).toBe(0);
|
||||
expect(root_child0.getComputedTop()).toBe(0);
|
@@ -5,6 +5,8 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import { Yoga } from "./tools/globals";
|
||||
|
||||
test("border_start", () => {
|
||||
const root = Yoga.Node.create();
|
||||
root.setWidth(100);
|
@@ -5,6 +5,8 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import { Yoga } from "./tools/globals";
|
||||
|
||||
test("margin_start", () => {
|
||||
const root = Yoga.Node.create();
|
||||
root.setWidth(100);
|
@@ -5,6 +5,8 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import { Yoga } from "./tools/globals";
|
||||
|
||||
test("padding_start", () => {
|
||||
const root = Yoga.Node.create();
|
||||
root.setWidth(100);
|
@@ -5,6 +5,8 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import { Yoga } from "./tools/globals";
|
||||
|
||||
test("dirtied", () => {
|
||||
const root = Yoga.Node.create();
|
||||
root.setAlignItems(Yoga.ALIGN_FLEX_START);
|
||||
@@ -17,8 +19,9 @@ test("dirtied", () => {
|
||||
root.setDirtiedFunc(() => {
|
||||
dirtied++;
|
||||
});
|
||||
|
||||
// only nodes with a measure function can be marked dirty
|
||||
root.setMeasureFunc(() => {});
|
||||
root.setMeasureFunc(() => ({ width: 0, height: 0 }));
|
||||
|
||||
expect(dirtied).toBe(0);
|
||||
|
||||
@@ -43,7 +46,7 @@ test("dirtied_propagation", () => {
|
||||
root_child0.setAlignItems(Yoga.ALIGN_FLEX_START);
|
||||
root_child0.setWidth(50);
|
||||
root_child0.setHeight(20);
|
||||
root_child0.setMeasureFunc(() => {});
|
||||
root_child0.setMeasureFunc(() => ({ width: 0, height: 0 }));
|
||||
root.insertChild(root_child0, 0);
|
||||
|
||||
const root_child1 = Yoga.Node.create();
|
||||
@@ -82,14 +85,14 @@ test("dirtied_hierarchy", () => {
|
||||
root_child0.setAlignItems(Yoga.ALIGN_FLEX_START);
|
||||
root_child0.setWidth(50);
|
||||
root_child0.setHeight(20);
|
||||
root_child0.setMeasureFunc(() => {});
|
||||
root_child0.setMeasureFunc(() => ({ width: 0, height: 0 }));
|
||||
root.insertChild(root_child0, 0);
|
||||
|
||||
const root_child1 = Yoga.Node.create();
|
||||
root_child1.setAlignItems(Yoga.ALIGN_FLEX_START);
|
||||
root_child1.setWidth(50);
|
||||
root_child1.setHeight(20);
|
||||
root_child1.setMeasureFunc(() => {});
|
||||
root_child0.setMeasureFunc(() => ({ width: 0, height: 0 }));
|
||||
root.insertChild(root_child1, 0);
|
||||
|
||||
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
|
||||
@@ -120,7 +123,7 @@ test("dirtied_reset", () => {
|
||||
root.setAlignItems(Yoga.ALIGN_FLEX_START);
|
||||
root.setWidth(100);
|
||||
root.setHeight(100);
|
||||
root.setMeasureFunc(() => {});
|
||||
root.setMeasureFunc(() => ({ width: 0, height: 0 }));
|
||||
|
||||
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
|
||||
|
||||
@@ -142,7 +145,7 @@ test("dirtied_reset", () => {
|
||||
root.setAlignItems(Yoga.ALIGN_FLEX_START);
|
||||
root.setWidth(100);
|
||||
root.setHeight(100);
|
||||
root.setMeasureFunc(() => {});
|
||||
root.setMeasureFunc(() => ({ width: 0, height: 0 }));
|
||||
|
||||
root.markDirty();
|
||||
|
@@ -5,6 +5,8 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import { Yoga } from "./tools/globals";
|
||||
|
||||
test("errata_all_contains_example_errata", () => {
|
||||
const config = Yoga.Config.create();
|
||||
config.setErrata(Yoga.ERRATA_ALL);
|
@@ -5,6 +5,8 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import { Yoga } from "./tools/globals";
|
||||
|
||||
test("flex_basis_auto", () => {
|
||||
const root = Yoga.Node.create();
|
||||
|
@@ -5,6 +5,8 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import { Yoga } from "./tools/globals";
|
||||
|
||||
import { getMeasureCounterMax } from "./tools/MeasureCounter";
|
||||
|
||||
test("measure_once_single_flexible_child", () => {
|
||||
@@ -14,14 +16,14 @@ test("measure_once_single_flexible_child", () => {
|
||||
root.setWidth(100);
|
||||
root.setHeight(100);
|
||||
|
||||
const measureCounter = getMeasureCounterMax(Yoga);
|
||||
const measureCounter = getMeasureCounterMax();
|
||||
|
||||
const root_child0 = Yoga.Node.create();
|
||||
root_child0.setMeasureFunc(measureCounter.inc);
|
||||
root_child0.setFlexGrow(1);
|
||||
root.insertChild(root_child0, 0);
|
||||
|
||||
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
|
||||
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
|
||||
|
||||
expect(measureCounter.get()).toBe(1);
|
||||
|
@@ -5,6 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import { Yoga } from "./tools/globals";
|
||||
import { getMeasureCounter } from "./tools/MeasureCounter";
|
||||
|
||||
test("dont_measure_single_grow_shrink_child", () => {
|
||||
@@ -19,7 +20,7 @@ test("dont_measure_single_grow_shrink_child", () => {
|
||||
root_child0.setFlexGrow(1);
|
||||
root_child0.setFlexShrink(1);
|
||||
root.insertChild(root_child0, 0);
|
||||
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
|
||||
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
|
||||
|
||||
expect(measureCounter.get()).toBe(0);
|
||||
|
||||
@@ -27,8 +28,11 @@ test("dont_measure_single_grow_shrink_child", () => {
|
||||
});
|
||||
|
||||
test("dont_fail_with_incomplete_measure_dimensions", () => {
|
||||
// @ts-expect-error Testing bad usage
|
||||
const heightOnlyCallback = getMeasureCounter(() => ({ height: 10 }));
|
||||
// @ts-expect-error Testing bad usage
|
||||
const widthOnlyCallback = getMeasureCounter(() => ({ width: 10 }));
|
||||
// @ts-expect-error Testing bad usage
|
||||
const emptyCallback = getMeasureCounter(() => ({}));
|
||||
|
||||
const root = Yoga.Node.create();
|
||||
@@ -47,7 +51,7 @@ test("dont_fail_with_incomplete_measure_dimensions", () => {
|
||||
node2.setMeasureFunc(widthOnlyCallback.inc);
|
||||
node3.setMeasureFunc(emptyCallback.inc);
|
||||
|
||||
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
|
||||
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
|
||||
|
||||
expect(heightOnlyCallback.get()).toBe(1);
|
||||
expect(widthOnlyCallback.get()).toBe(1);
|
Reference in New Issue
Block a user