Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding some tests for checking the spreading behaviour of objects returned by a worklet. #180

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
35 changes: 35 additions & 0 deletions example/Tests/worklet-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,41 @@ export const worklet_tests = {
});
return ExpectValue(result, 42);
},
check_jsi_object_is_spreadable_after_worklet: async () => {
const func = () => {
"worklet";
return { a: 100 };
};
const result = Worklets.defaultContext.runAsync(func);
const spreadObject = { ...result };
return ExpectValue(spreadObject, { a: 100 });
},
check_jsi_object_is_assignable_after_worklet: async () => {
const func = () => {
"worklet";
return { a: 100 };
};
const result = Worklets.defaultContext.runAsync(func);
const assignedObject = Object.assign({}, result);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the problem was when using Object.assign/spread inside a Worklet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I have added a test below to show that spreading inside the worklet works as expected.
My use case was to spread the object that is returned by the worklet, and I have not spread inside worklet in production code, so I have no further experience with it.

return ExpectValue(assignedObject, { a: 100 });
},
check_jsi_object_is_spreadable_inside_worklet: async () => {
const func = () => {
"worklet";
const testObject = { a: 100, b: "200" };
return { ...testObject };
};
const result = Worklets.defaultContext.runAsync(func);
return ExpectValue(result, { a: 100, b: "200" });
},
check_jsi_object_is_returned_from_worklet: async () => {
const func = () => {
"worklet";
return { a: 100, b: "200" };
};
const result = Worklets.defaultContext.runAsync(func);
return ExpectValue(result, { a: 100, b: "200" });
},
check_worklet_checker_works: () => {
const func = () => {
"worklet";
Expand Down
Loading