Skip to content

Commit

Permalink
Add a mock implementation for test runners (#276)
Browse files Browse the repository at this point in the history
I was recently using reanimated in react-navigation where I needed to mock it to be able to run it in Jest. It'll be great if the mock was in the library so we don't have to duplicate it in every project.

I looked through the typescript definitions and added a mock function for almost everything. I didn't use anything specific to a test runner such as Jest, so it should be possible to use the mock with any test runner.
  • Loading branch information
satya164 authored and osdnk committed May 21, 2019
1 parent 60079d8 commit 6444602
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 1 deletion.
119 changes: 119 additions & 0 deletions mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
* Mock implementation for test runners.
*
* Example:
*
* ```js
* jest.mock('react-native-reanimated', () => require('react-native-reanimated/mock'));
* ```
*/

const React = require('react');
const { View, Text, Image, ScrollView } = require('react-native');

const NOOP = () => undefined;

class Code extends React.Component {
render() {
return null;
}
}

module.exports = {
__esModule: true,

default: {
SpringUtils: {
makeDefaultConfig: NOOP,
makeConfigFromBouncinessAndSpeed: NOOP,
makeConfigFromOrigamiTensionAndFriction: NOOP,
},

View,
Text,
Image,
ScrollView,
Code,

Clock: NOOP,
Node: NOOP,
Value: NOOP,

Extrapolate: {
EXTEND: 'extend',
CLAMP: 'clamp',
IDENTITY: 'identity',
},

add: NOOP,
sub: NOOP,
multiply: NOOP,
divide: NOOP,
pow: NOOP,
modulo: NOOP,
sqrt: NOOP,
sin: NOOP,
cos: NOOP,
tan: NOOP,
acos: NOOP,
asin: NOOP,
atan: NOOP,
exp: NOOP,
round: NOOP,
floor: NOOP,
ceil: NOOP,
lessThan: NOOP,
eq: NOOP,
greaterThan: NOOP,
lessOrEq: NOOP,
greaterOrEq: NOOP,
neq: NOOP,
and: NOOP,
or: NOOP,
defined: NOOP,
not: NOOP,
set: NOOP,
concat: NOOP,
cond: NOOP,
block: NOOP,
call: NOOP,
debug: NOOP,
onChange: NOOP,
startClock: NOOP,
stopClock: NOOP,
clockRunning: NOOP,
event: NOOP,
abs: NOOP,
acc: NOOP,
color: NOOP,
diff: NOOP,
diffClamp: NOOP,
interpolate: NOOP,
max: NOOP,
min: NOOP,

decay: NOOP,
timing: NOOP,
spring: NOOP,

useCode: NOOP,
},

Easing: {
linear: NOOP,
ease: NOOP,
quad: NOOP,
cubic: NOOP,
poly: () => NOOP,
sin: NOOP,
circle: NOOP,
exp: NOOP,
elastic: () => NOOP,
back: () => NOOP,
bounce: () => NOOP,
bezier: () => NOOP,
in: () => NOOP,
out: () => NOOP,
inOut: () => NOOP,
},
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"ios/",
"RNReanimated.podspec",
"README.md",
"react-native-reanimated.d.ts"
"react-native-reanimated.d.ts",
"mock.js"
],
"repository": {
"type": "git",
Expand Down

0 comments on commit 6444602

Please sign in to comment.