Skip to content

Commit 14e60f7

Browse files
committed
checkpoint: RN types on useUser
1 parent 76a33ba commit 14e60f7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

examples/react-native/__tests__/ts/app-services/atlas-functions.test.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ function MyApp() {
3434
<UserProvider>
3535
<Text>Foo!</Text>
3636
<Addition />
37+
<AdditionWithTypes />
3738
</UserProvider>
3839
</View>
3940
) : null;
4041
}
4142

4243
let higherScopedSum: number;
44+
let typedHigherScopedSum: number;
4345
// :remove-end:
4446

4547
function Addition() {
@@ -68,6 +70,27 @@ function Addition() {
6870
// :remove-end:
6971
}
7072
// :snippet-end:
73+
// :snippet-start: addition-with-types
74+
type FunctionTypes = {
75+
sum: (a: number, b: number) => number;
76+
} & Realm.DefaultFunctionsFactory;
77+
78+
function AdditionWithTypes() {
79+
const user = useUser<FunctionTypes, SimpleObject, Realm.DefaultUserProfileData>();
80+
async function addNumbers(numA: number, numB: number) {
81+
const sum = await user?.functions.sum(numA, numB);
82+
// :remove-start:
83+
expect(sum).toBe(3);
84+
typedHigherScopedSum = sum as number;
85+
// :remove-end:
86+
return sum;
87+
}
88+
// ...
89+
// :remove-start:
90+
return <Button onPress={() => addNumbers(1, 2)} testID='test-typed-function-call' title='Test Me!' />;
91+
// :remove-end:
92+
}
93+
// :snippet-end:
7194

7295
afterEach(async () => await App.getApp(APP_ID).currentUser?.logOut());
7396

@@ -78,3 +101,10 @@ test('Call Atlas Function', async () => {
78101
fireEvent.press(button);
79102
await waitFor(() => expect(higherScopedSum).toBe(3));
80103
});
104+
test('Call Typed Atlas Function', async () => {
105+
const {getByTestId} = render(<AppWrapper />);
106+
107+
const button = await waitFor(() => getByTestId('test-typed-function-call'));
108+
fireEvent.press(button);
109+
await waitFor(() => expect(higherScopedSum).toBe(3));
110+
});

0 commit comments

Comments
 (0)