1
- import { Worklets } from ' react-native-worklets' ;
2
- import { Expect , ExpectException , ExpectValue } from ' ./utils' ;
1
+ import { Worklets } from " react-native-worklets" ;
2
+ import { Expect , ExpectException , ExpectValue } from " ./utils" ;
3
3
4
4
export const sharedvalue_tests = {
5
5
get_set_numeric_value : ( ) => {
@@ -20,62 +20,62 @@ export const sharedvalue_tests = {
20
20
} ,
21
21
22
22
get_set_string_value : ( ) => {
23
- const sharedValue = Worklets . createSharedValue ( ' hello world' ) ;
24
- sharedValue . value = ' hello worklet' ;
25
- return ExpectValue ( sharedValue . value , ' hello worklet' ) ;
23
+ const sharedValue = Worklets . createSharedValue ( " hello world" ) ;
24
+ sharedValue . value = " hello worklet" ;
25
+ return ExpectValue ( sharedValue . value , " hello worklet" ) ;
26
26
} ,
27
27
28
28
get_set_object_value : ( ) => {
29
- const sharedValue = Worklets . createSharedValue ( { a : 100 , b : 200 } ) ;
29
+ const sharedValue = Worklets . createSharedValue ( { a : 100 , b : 200 } ) ;
30
30
sharedValue . value . a = 50 ;
31
31
sharedValue . value . b = 100 ;
32
- return ExpectValue ( sharedValue . value , { a : 50 , b : 100 } ) ;
32
+ return ExpectValue ( sharedValue . value , { a : 50 , b : 100 } ) ;
33
33
} ,
34
34
35
35
get_set_array_value : ( ) => {
36
36
const sharedValue = Worklets . createSharedValue ( [ 100 , 50 ] ) ;
37
37
return ExpectValue ( sharedValue . value [ 0 ] , 100 ) . then ( ( ) =>
38
- ExpectValue ( sharedValue . value [ 1 ] , 50 ) ,
38
+ ExpectValue ( sharedValue . value [ 1 ] , 50 )
39
39
) ;
40
40
} ,
41
41
42
42
box_number_to_string : ( ) => {
43
43
const sharedValue = Worklets . createSharedValue ( 100 ) ;
44
44
// @ts -ignore
45
- sharedValue . value = ' 100' ;
46
- return ExpectValue ( sharedValue . value , ' 100' ) ;
45
+ sharedValue . value = " 100" ;
46
+ return ExpectValue ( sharedValue . value , " 100" ) ;
47
47
} ,
48
48
49
49
box_string_to_number : ( ) => {
50
- const sharedValue = Worklets . createSharedValue ( ' 100' ) ;
50
+ const sharedValue = Worklets . createSharedValue ( " 100" ) ;
51
51
// @ts -ignore
52
52
sharedValue . value = 100 ;
53
53
return ExpectValue ( sharedValue . value , 100 ) ;
54
54
} ,
55
55
56
56
box_string_to_array : ( ) => {
57
- const sharedValue = Worklets . createSharedValue ( ' 100' ) ;
57
+ const sharedValue = Worklets . createSharedValue ( " 100" ) ;
58
58
// @ts -ignore
59
59
sharedValue . value = [ 100 , 200 ] ;
60
60
return ExpectValue ( sharedValue . value , [ 100 , 200 ] ) ;
61
61
} ,
62
62
63
63
box_string_to_object : ( ) => {
64
- const sharedValue = Worklets . createSharedValue ( ' 100' ) ;
64
+ const sharedValue = Worklets . createSharedValue ( " 100" ) ;
65
65
// @ts -ignore
66
- sharedValue . value = { a : 100 , b : 200 } ;
67
- return ExpectValue ( sharedValue . value , { a : 100 , b : 200 } ) ;
66
+ sharedValue . value = { a : 100 , b : 200 } ;
67
+ return ExpectValue ( sharedValue . value , { a : 100 , b : 200 } ) ;
68
68
} ,
69
69
70
70
box_array_to_object : ( ) => {
71
71
const sharedValue = Worklets . createSharedValue ( [ 100 , 200 ] ) ;
72
72
// @ts -ignore
73
- sharedValue . value = { a : 100 , b : 200 } ;
74
- return ExpectValue ( sharedValue . value , { a : 100 , b : 200 } ) ;
73
+ sharedValue . value = { a : 100 , b : 200 } ;
74
+ return ExpectValue ( sharedValue . value , { a : 100 , b : 200 } ) ;
75
75
} ,
76
76
77
77
box_object_to_array : ( ) => {
78
- const sharedValue = Worklets . createSharedValue ( { a : 100 , b : 200 } ) ;
78
+ const sharedValue = Worklets . createSharedValue ( { a : 100 , b : 200 } ) ;
79
79
// @ts -ignore
80
80
sharedValue . value = [ 100.34 , 200 ] ;
81
81
return ExpectValue ( sharedValue . value , [ 100.34 , 200 ] ) ;
@@ -95,8 +95,8 @@ export const sharedvalue_tests = {
95
95
96
96
array_destructure_to_object : ( ) => {
97
97
const sharedValue = Worklets . createSharedValue ( [ 100 , 200 ] ) ;
98
- const p = { ...sharedValue . value } ;
99
- return ExpectValue ( p , { 0 : 100 , 1 : 200 } ) ;
98
+ const p = { ...sharedValue . value } ;
99
+ return ExpectValue ( p , { 0 : 100 , 1 : 200 } ) ;
100
100
} ,
101
101
102
102
array_length : ( ) => {
@@ -105,35 +105,35 @@ export const sharedvalue_tests = {
105
105
} ,
106
106
107
107
object_value_destructure : ( ) => {
108
- const sharedValue = Worklets . createSharedValue ( { a : 100 , b : 200 } ) ;
109
- const { a, b} = { ...sharedValue . value } ;
110
- return ExpectValue ( { a, b} , { a : 100 , b : 100 } ) ;
108
+ const sharedValue = Worklets . createSharedValue ( { a : 100 , b : 200 } ) ;
109
+ const { a, b } = { ...sharedValue . value } ;
110
+ return ExpectValue ( { a, b } , { a : 100 , b : 100 } ) ;
111
111
} ,
112
112
113
113
object_value_spread : ( ) => {
114
- const sharedValue = Worklets . createSharedValue ( { a : 100 , b : 200 } ) ;
115
- const p = { ...sharedValue . value } ;
116
- return ExpectValue ( p , { a : 100 , b : 200 } ) ;
114
+ const sharedValue = Worklets . createSharedValue ( { a : 100 , b : 200 } ) ;
115
+ const p = { ...sharedValue . value } ;
116
+ return ExpectValue ( p , { a : 100 , b : 200 } ) ;
117
117
} ,
118
118
119
119
set_value_from_worklet : ( ) => {
120
- const sharedValue = Worklets . createSharedValue ( ' hello world' ) ;
120
+ const sharedValue = Worklets . createSharedValue ( " hello world" ) ;
121
121
const worklet = Worklets . createRunInContextFn ( function ( ) {
122
- ' worklet' ;
123
- sharedValue . value = ' hello worklet' ;
122
+ " worklet" ;
123
+ sharedValue . value = " hello worklet" ;
124
124
} ) ;
125
- sharedValue . value = ' hello worklet' ;
125
+ sharedValue . value = " hello worklet" ;
126
126
return Expect ( worklet ( ) , ( ) =>
127
- sharedValue . value === ' hello worklet'
127
+ sharedValue . value === " hello worklet"
128
128
? undefined
129
- : `Expected ${ "'hello worklet'" } but got ${ sharedValue . value } ` ,
129
+ : `Expected ${ "'hello worklet'" } but got ${ sharedValue . value } `
130
130
) ;
131
131
} ,
132
132
133
133
set_function_with_error : ( ) => {
134
134
return ExpectException ( ( ) => {
135
135
Worklets . createSharedValue ( ( ) => { } ) ;
136
- } , ' Regular javascript functions cannot be shared.' ) ;
136
+ } , " Regular javascript functions cannot be shared." ) ;
137
137
} ,
138
138
139
139
add_listener : ( ) => {
@@ -149,12 +149,12 @@ export const sharedvalue_tests = {
149
149
add_listener_from_worklet_should_fail : ( ) => {
150
150
const sharedValue = Worklets . createSharedValue ( 100 ) ;
151
151
const worklet = Worklets . createRunInContextFn ( function ( ) {
152
- ' worklet' ;
152
+ " worklet" ;
153
153
sharedValue . addListener ( ( ) => { } ) ;
154
154
} ) ;
155
155
return ExpectException (
156
156
worklet ,
157
- ' addListener can only be called from the main Javascript context and not from a worklet.' ,
157
+ " addListener can only be called from the main Javascript context and not from a worklet."
158
158
) ;
159
159
} ,
160
160
} ;
0 commit comments