Skip to content

Conversation

@Latropos
Copy link
Contributor

@Latropos Latropos commented Nov 23, 2023

Summary

This PR comes with mikro-framework for Reanimated public API runtime tests
Based on: #5406

Example usage

1. Create testing container in your application

import React from 'react';
import RuntimeTestsRunner from './ReanimatedRuntimeTestsRunner/RuntimeTestsRunner';

import './Animations.test'; // import tests

export default function RuntimeTestsExample() {
  return <RuntimeTestsRunner />;
}

2. Implement tests Animations.test.ts

import React, { useEffect } from 'react';
import { View } from 'react-native';
import Animated, { useSharedValue, useAnimatedStyle, withTiming } from 'react-native-reanimated';
import { describe, test, expect, render, useTestRef, getTestComponent, wait } from './ReanimatedRuntimeTestsRunner/RuntimeTestsApi';

const AnimatedComponent = () => {
  const widthSV = useSharedValue(0);
  const ref = useTestRef('AnimatedComponent');

  const style = useAnimatedStyle(() => ( {
    width: withTiming(widthSV.value, { duration: 500 }),
  }));

  useEffect(() => {
    widthSV.value = 100;
  }, [widthSV]);

  return (
    <View
      style={{ flex: 1, flexDirection: 'column' }}>
      <Animated.View
        ref={ref}
        style={[{ height: 80,  backgroundColor: 'blue' }, style]}
      />
    </View>
  );
};

describe('Tests of animations', () => {
  test('withTiming - expect pass', async () => {
    await render(<AnimatedComponent />);
    const component = getTestComponent('AnimatedComponent');
    await wait(600);
    expect(await component.getAnimatedStyle('width')).toBe('100');
  });
});

API

  • describe
  • test
  • expect
  • render
  • useTestRef
  • getTestComponent
  • component.getAnimatedStyle
  • mockAnimationTimer
  • recordAnimationUpdates
  • updatesContainer.getUpdates
  • updatesContainer.getNativeSnapshots
  • callTracker
  • callTrackerFn
  • getTrackerCallCount
  • registerValue
  • getRegisteredValue
  • Presets
  • notify
  • waitForNotify
  • wait

@piaskowyk piaskowyk changed the base branch from main to @piaskowyk/runtime-tests November 24, 2023 12:59
@piaskowyk piaskowyk changed the title Runtime test, Work in progress [1] Runtime test, Work in progress Nov 24, 2023
@Latropos Latropos force-pushed the acynk/runtime-tests branch 2 times, most recently from 7bdbb56 to 1f1a22e Compare November 27, 2023 08:17
@Latropos Latropos requested review from tjzel and tomekzaw February 23, 2024 10:09
@Latropos Latropos requested a review from tomekzaw February 26, 2024 12:53
Copy link
Collaborator

@tjzel tjzel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get this bad boy merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants