diff --git a/core/engine/src/builtins/array/tests.rs b/core/engine/src/builtins/array/tests.rs index 7f8d2d98f72..ee594fbb1e6 100644 --- a/core/engine/src/builtins/array/tests.rs +++ b/core/engine/src/builtins/array/tests.rs @@ -962,3 +962,26 @@ fn array_of_neg_zero() { TestAction::assert("arr.every(x => (1/x) === -Infinity)"), ]); } + +#[test] +fn array_prototype_find_edge_cases() { + run_test_actions([ + TestAction::run_harness(), + TestAction::assert("[].find(x => x === 1) === undefined"), + TestAction::assert("[1, 2, 3].find(x => x === 99) === undefined"), + TestAction::assert("[1, 2, 1].find(x => x === 1) === 1"), + TestAction::assert(indoc! {r#" + var obj = { name: "Alice" }; + [obj].find(x => x.name === "Alice") === obj + "#}), + TestAction::assert(indoc! {r#" + var idx = -1; + [10, 20, 30].find((v, i) => { idx = i; return v === 20; }); + idx === 1 + "#}), + TestAction::assert(indoc! {r#" + let arr = [1, , 3]; + arr.find(x => x === undefined) === undefined + "#}), + ]); +}