Skip to content

Commit 192f8a5

Browse files
committed
test: add harness test for Auto dataBind with no default ViewModel
1 parent f53aa05 commit 192f8a5

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

example/__tests__/autoplay.harness.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import type { ViewModelInstance } from '@rive-app/react-native';
2121
// Source: https://rive.app/community/files/25997-48571-demo-for-tracking-rive-property-in-react-native/
2222
const BOUNCING_BALL = require('../assets/rive/bouncing_ball.riv');
2323

24+
// Simple animation with ViewModels defined but no default ViewModel assigned to the artboard
25+
// Source: https://rive.app/community/files/27026-50856-no-default-vm-for-artboard/
26+
const NO_DEFAULT_VM = require('../assets/rive/nodefaultbouncing.riv');
27+
2428
function expectDefined<T>(value: T): asserts value is NonNullable<T> {
2529
expect(value).toBeDefined();
2630
}
@@ -264,3 +268,39 @@ describe('autoPlay prop (issue #138)', () => {
264268
cleanup();
265269
});
266270
});
271+
272+
describe('Auto dataBind with no default ViewModel (issue #189)', () => {
273+
it('plays without error when file has ViewModels but no artboard default', async () => {
274+
const file = await RiveFileFactory.fromSource(NO_DEFAULT_VM, undefined);
275+
276+
const context: TestContext = { ref: null, error: null };
277+
await render(
278+
<View style={{ width: 200, height: 200 }}>
279+
<RiveView
280+
hybridRef={{
281+
f: (ref: RiveViewRef | null) => {
282+
context.ref = ref;
283+
},
284+
}}
285+
style={{ flex: 1 }}
286+
file={file}
287+
autoPlay={true}
288+
fit={Fit.Contain}
289+
onError={(e) => {
290+
context.error = e.message;
291+
}}
292+
/>
293+
</View>
294+
);
295+
296+
await waitFor(
297+
() => {
298+
expect(context.ref).not.toBeNull();
299+
},
300+
{ timeout: 5000 }
301+
);
302+
303+
expect(context.error).toBeNull();
304+
cleanup();
305+
});
306+
});
319 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)