Skip to content

Commit ecf0213

Browse files
committed
test(harness): assert first listener emission fires without prop update
1 parent 8a86cb8 commit ecf0213

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

example/__tests__/hooks.harness.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,34 @@ function expectDefined<T>(value: T): asserts value is NonNullable<T> {
9696
}
9797

9898
describe('useRiveNumber Hook', () => {
99+
it('starts undefined then receives value via listener', async () => {
100+
const file = await RiveFileFactory.fromSource(QUICK_START, undefined);
101+
const vm = file.defaultArtboardViewModel();
102+
expectDefined(vm);
103+
const instance = vm.createDefaultInstance();
104+
expectDefined(instance);
105+
106+
const context = createUseRiveNumberContext();
107+
108+
// Value must start undefined — not synchronously read from property.value
109+
expect(context.value).toBeUndefined();
110+
111+
await render(
112+
<UseRiveNumberTestComponent instance={instance} context={context} />
113+
);
114+
115+
// After listener fires, value should be a number
116+
await waitFor(
117+
() => {
118+
expect(context.error).toBeNull();
119+
expect(typeof context.value).toBe('number');
120+
},
121+
{ timeout: 5000 }
122+
);
123+
124+
cleanup();
125+
});
126+
99127
it('returns value from number property', async () => {
100128
const file = await RiveFileFactory.fromSource(QUICK_START, undefined);
101129
const vm = file.defaultArtboardViewModel();

0 commit comments

Comments
 (0)