UNPKG

react-native-reanimated-carousel

Version:

Simple carousel component.fully implemented using Reanimated 2.Infinitely scrolling, very smooth.

2 lines 4.62 kB
var _reactNativeReanimated=require("react-native-reanimated");var _dealWithAnimation=require("./deal-with-animation");jest.mock("react-native-reanimated",function(){return{withSpring:jest.fn(function(value,_config,callback){callback==null?void 0:callback(true);return value;}),withTiming:jest.fn(function(value,_config,callback){callback==null?void 0:callback(true);return value;})};});describe("dealWithAnimation",function(){beforeEach(function(){jest.clearAllMocks();});it("should handle spring animation",function(){var callback=jest.fn();var springConfig={damping:20,stiffness:90};var animation=(0,_dealWithAnimation.dealWithAnimation)({type:"spring",config:springConfig});var result=animation(100,callback);expect(_reactNativeReanimated.withSpring).toHaveBeenCalledWith(100,springConfig,expect.any(Function));expect(callback).toHaveBeenCalledWith(true);expect(result).toBe(100);});it("should handle timing animation",function(){var callback=jest.fn();var timingConfig={duration:300};var animation=(0,_dealWithAnimation.dealWithAnimation)({type:"timing",config:timingConfig});var result=animation(100,callback);expect(_reactNativeReanimated.withTiming).toHaveBeenCalledWith(100,timingConfig,expect.any(Function));expect(callback).toHaveBeenCalledWith(true);expect(result).toBe(100);});it("should pass animation config correctly",function(){var springConfig={damping:10,mass:1,stiffness:100};var animation=(0,_dealWithAnimation.dealWithAnimation)({type:"spring",config:springConfig});animation(100,jest.fn());expect(_reactNativeReanimated.withSpring).toHaveBeenCalledWith(100,expect.objectContaining(springConfig),expect.any(Function));});it("should handle animation completion",function(){var callback=jest.fn();var animation=(0,_dealWithAnimation.dealWithAnimation)({type:"timing",config:{duration:300}});animation(100,callback);expect(callback).toHaveBeenCalledWith(true);});it("should handle spring animation with different values",function(){var callback=jest.fn();var animation=(0,_dealWithAnimation.dealWithAnimation)({type:"spring",config:{damping:15}});animation(0,callback);animation(-100,callback);animation(500,callback);expect(_reactNativeReanimated.withSpring).toHaveBeenCalledWith(0,{damping:15},expect.any(Function));expect(_reactNativeReanimated.withSpring).toHaveBeenCalledWith(-100,{damping:15},expect.any(Function));expect(_reactNativeReanimated.withSpring).toHaveBeenCalledWith(500,{damping:15},expect.any(Function));expect(callback).toHaveBeenCalledTimes(3);});it("should handle timing animation with different values",function(){var callback=jest.fn();var animation=(0,_dealWithAnimation.dealWithAnimation)({type:"timing",config:{duration:500}});animation(0,callback);animation(-50,callback);animation(1000,callback);expect(_reactNativeReanimated.withTiming).toHaveBeenCalledWith(0,{duration:500},expect.any(Function));expect(_reactNativeReanimated.withTiming).toHaveBeenCalledWith(-50,{duration:500},expect.any(Function));expect(_reactNativeReanimated.withTiming).toHaveBeenCalledWith(1000,{duration:500},expect.any(Function));expect(callback).toHaveBeenCalledTimes(3);});it("should handle empty spring config",function(){var callback=jest.fn();var animation=(0,_dealWithAnimation.dealWithAnimation)({type:"spring",config:{}});animation(100,callback);expect(_reactNativeReanimated.withSpring).toHaveBeenCalledWith(100,{},expect.any(Function));expect(callback).toHaveBeenCalledWith(true);});it("should handle empty timing config",function(){var callback=jest.fn();var animation=(0,_dealWithAnimation.dealWithAnimation)({type:"timing",config:{}});animation(100,callback);expect(_reactNativeReanimated.withTiming).toHaveBeenCalledWith(100,{},expect.any(Function));expect(callback).toHaveBeenCalledWith(true);});it("should handle fractional values",function(){var callback=jest.fn();var animation=(0,_dealWithAnimation.dealWithAnimation)({type:"spring",config:{damping:10}});animation(50.5,callback);animation(-25.75,callback);expect(_reactNativeReanimated.withSpring).toHaveBeenCalledWith(50.5,{damping:10},expect.any(Function));expect(_reactNativeReanimated.withSpring).toHaveBeenCalledWith(-25.75,{damping:10},expect.any(Function));});it("should create different animation functions for different configs",function(){var animation1=(0,_dealWithAnimation.dealWithAnimation)({type:"spring",config:{damping:10}});var animation2=(0,_dealWithAnimation.dealWithAnimation)({type:"timing",config:{duration:200}});expect(animation1).not.toBe(animation2);expect(typeof animation1).toBe("function");expect(typeof animation2).toBe("function");});}); //# sourceMappingURL=deal-with-animation.test.js.map