Skip to content

Commit

Permalink
[reJest] Migrate to use the new runtimetests API (#6356)
Browse files Browse the repository at this point in the history
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary
Replace all uses of `FAILING` and `WARN` test decorators with
`expect().toThrow()`
The full removal of the logic behind these decorators is located here:
#6358
<!-- Explain the motivation for this PR. Include "Fixes #<number>" if
applicable. -->

## Test plan

<!-- Provide a minimal but complete code snippet that can be used to
test out this change along with instructions how to run it and a
description of the expected behavior. -->
  • Loading branch information
Latropos authored Aug 12, 2024
1 parent 4ff82bd commit c0fe534
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,6 @@ const LayoutAnimation = () => {
);
};

function WarningComponent() {
console.warn('message');
return <View />;
}

describe('Tests of Test Framework', () => {
test('Test comparators', () => {
expect(1).toBe(1.0);
Expand Down Expand Up @@ -295,10 +290,6 @@ describe('Tests of Test Framework', () => {
expect(await component.getAnimatedStyle('width')).toBe('100');
});

test.warn('warning test', 'message', async () => {
await render(<WarningComponent />);
});

describe('Test .toThrow()', () => {
test('Warn with no error message - expect pass', async () => {
await expect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ describe('Test *****useFrameCallback*****', () => {

return <View />;
};
test.failing(
'frameCallback should be workletized',
'ReanimatedError: [Reanimated] Tried to synchronously call a non-worklet function `imNotAWorklet` on the UI thread.\nSee https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-synchronously-call-a-non-worklet-function-on-the-ui-thread for more details., js engine: reanimated',
async () => {

test('frameCallback should be workletized', async () => {
await expect(async () => {
await render(<InvalidFrameCallback />);
await wait(200);
},
);
}).toThrow(
'ReanimatedError: [Reanimated] Tried to synchronously call a non-worklet function `imNotAWorklet` on the UI thread.\nSee https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-synchronously-call-a-non-worklet-function-on-the-ui-thread for more details., js engine: reanimated',
);
});
});
});

const styles = StyleSheet.create({
container: {
flex: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,58 +71,50 @@ describe('WithSpring snapshots 📸, test various configs', () => {
});

describe('Invalid configuration, test warning', () => {
test.warn(
'Invalid mass and stiffness, config is { mass: -40, stiffness: -400 }',
'[Reanimated] Invalid spring config, stiffness must be grater than zero but got -400, mass must be grater than zero but got -40',
async () => {
test('Invalid mass and stiffness, config is { mass: -40, stiffness: -400 }', async () => {
await expect(async () => {
await render(<AnimatedComponent animateFrom={30} animateTo={300} config={{ mass: -40, stiffness: -400 }} />);
},
);
}).toThrow(
'[Reanimated] Invalid spring config, stiffness must be grater than zero but got -400, mass must be grater than zero but got -40',
);
});

test.warn.each([
test.each([
{ mass: 0, stiffness: 5000 },
{ mass: 0 },
{ mass: -10 },
{ mass: -5, duration: 5000 },
{ mass: -5, damping: 50 },
{ mass: -20, stiffness: 20 },
])(
'%# Invalid mass, config is %p',
'[Reanimated] Invalid spring config, mass must be grater than zero but got ${mass}',
async config => {
])('%# Invalid mass, config is %p', async config => {
await expect(async () => {
await render(<AnimatedComponent animateFrom={30} animateTo={300} config={config as any} />);
},
);
}).toThrow(`[Reanimated] Invalid spring config, mass must be grater than zero but got ${config.mass}`);
});

test.warn.each([
test.each([
{ stiffness: -20 },
{ stiffness: 0 },
{ damping: 20, stiffness: -20 },
{ mass: 20, stiffness: -20 },
{ mass: 20, stiffness: 0 },
])(
'%# Invalid stiffness, config is %p',
'[Reanimated] Invalid spring config, stiffness must be grater than zero but got ${stiffness}',
async config => {
])('%# Invalid stiffness, config is %p', async config => {
await expect(async () => {
await render(<AnimatedComponent animateFrom={30} animateTo={300} config={config} />);
},
);
}).toThrow(`[Reanimated] Invalid spring config, stiffness must be grater than zero but got ${config.stiffness}`);
});

test.warn.each([{ damping: -20 }, { damping: 0 }])(
'%# Invalid damping, config is %p',
'[Reanimated] Invalid spring config, damping must be grater than zero but got ${damping}',
async config => {
test.each([{ damping: -20 }, { damping: 0 }])('%# Invalid damping, config is %p', async config => {
await expect(async () => {
await render(<AnimatedComponent animateFrom={30} animateTo={300} config={config} />);
},
);
}).toThrow(`[Reanimated] Invalid spring config, damping must be grater than zero but got ${config.damping}`);
});

test.warn.each([{ duration: -20 }])(
'%# Invalid duration, config is %p',
"[Reanimated] Invalid spring config, duration can't be negative, got ${duration}",
async config => {
test.each([{ duration: -20 }])('%# Invalid duration, config is %p', async config => {
await expect(async () => {
await render(<AnimatedComponent animateFrom={30} animateTo={300} config={config} />);
},
);
}).toThrow(`[Reanimated] Invalid spring config, duration can't be negative, got ${config.duration}`);
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,20 @@ async function getSnapshotUpdates(easingFn: EasingFunction | EasingFunctionFacto

describe('withTiming snapshots 📸, test EASING', () => {
describe('Invalid easing', () => {
test.failing(
'Easing imported from react-native throws an error',
'Error: [Reanimated] The easing function is not a worklet. Please make sure you import `Easing` from react-native-reanimated.',
async () => {
test('Easing imported from react-native throws an error', async () => {
await expect(async () => {
await render(
<ErrorBoundary>
<ActiveAnimatedComponent easing={EasingRN.linear} />
</ErrorBoundary>,
);
await wait(1200);
},
);
}).toThrow(
'Error: [Reanimated] The easing function is not a worklet. Please make sure you import `Easing` from react-native-reanimated.',
);
});

test.failing(
'Easing must be a worklet, otherwise it throws an error',
'Error: [Reanimated] The easing function is not a worklet. Please make sure you import `Easing` from react-native-reanimated.',
async () => {
test('Easing must be a worklet, otherwise it throws an error', async () => {
await expect(async () => {
await render(
<ErrorBoundary>
<ActiveAnimatedComponent
Expand All @@ -108,9 +105,10 @@ describe('withTiming snapshots 📸, test EASING', () => {
/>
</ErrorBoundary>,
);
await wait(1200);
},
);
}).toThrow(
'Error: [Reanimated] The easing function is not a worklet. Please make sure you import `Easing` from react-native-reanimated.',
);
});
});

test('No easing function', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,17 @@ describe('Tests of *****sharedValue*****', () => {
},
);

test.failing.each([...Presets.stringObjects, ...Presets.dates, ...Presets.unserializableObjects])(
test.each([...Presets.stringObjects, ...Presets.dates, ...Presets.unserializableObjects])(
'Test object %p causes an error',
'ReanimatedError: [Reanimated] Trying to access property `onFrame` of an object which cannot be sent to the UI runtime., js engine: reanimated',
async testedValue => {
await render(<SharedValueComponent initialValue={testedValue} progress={0} />);

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _sharedValue = await getRegisteredValue(SHARED_VALUE_REF);

await render(<ProgressBar progress={0} />);
await expect(async () => {
await render(<SharedValueComponent initialValue={testedValue} progress={0} />);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _sharedValue = await getRegisteredValue(SHARED_VALUE_REF);
await render(<ProgressBar progress={0} />);
}).toThrow(
'ReanimatedError: [Reanimated] Trying to access property `onFrame` of an object which cannot be sent to the UI runtime., js engine: reanimated',
);
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe('Test JUMPING transition modifiers', () => {
});
});

describe.only('Test CURVED transition modifiers', () => {
describe('Test CURVED transition modifiers', () => {
test.each([
[CurvedTransition, 'default'],
[CurvedTransition.duration(300), 'default'], // the default duration is 300
Expand Down

0 comments on commit c0fe534

Please sign in to comment.