-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
379 additions
and
1,767 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
module.exports = { | ||
presets: ["module:metro-react-native-babel-preset"], | ||
plugins: [ | ||
"@babel/plugin-proposal-class-properties", | ||
"@babel/plugin-proposal-private-methods", | ||
"react-native-reanimated/plugin", | ||
"inline-dotenv", | ||
"@babel/plugin-syntax-dynamic-import", | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require("react-native-reanimated").setUpTests(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
preset: "react-native", | ||
modulePathIgnorePatterns: [ | ||
"example", | ||
"docs", | ||
"assets", | ||
".yarn", | ||
"lib", | ||
".eslintrc", | ||
], | ||
setupFiles: ["./jest-setup.js"], | ||
setupFilesAfterEnv: ["@testing-library/jest-native/extend-expect"], | ||
testEnvironment: "node", | ||
transformIgnorePatterns: [], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { FC } from "react"; | ||
import React from "react"; | ||
import Animated, { useAnimatedStyle, useDerivedValue } from "react-native-reanimated"; | ||
import renderer from "react-test-renderer"; | ||
|
||
describe("useSharedValue", () => { | ||
it("retains value on rerender", () => { | ||
const initialValue = 0; | ||
const updatedValue = 1; | ||
|
||
interface Props { | ||
key: string | ||
value: number | ||
} | ||
|
||
const TestComponent: FC<Props> = (props) => { | ||
const opacity = useDerivedValue(() => props.value, [props.value]); | ||
const animatedStyle = useAnimatedStyle(() => ({ | ||
opacity: opacity.value, | ||
}), [opacity]); | ||
|
||
return <Animated.View style={animatedStyle} />; | ||
}; | ||
|
||
// When rendering with initial value | ||
const wrapper = renderer.create(<TestComponent key="box" value={initialValue} />); | ||
|
||
expect( | ||
typeof wrapper.root.children[0] !== "string" | ||
? wrapper.root.children[0].props.style.animatedStyle.current.value.opacity | ||
: false, | ||
).toBe(initialValue); | ||
|
||
// When rendering with updated value | ||
wrapper.update(<TestComponent key="box" value={updatedValue} />); | ||
|
||
expect( | ||
typeof wrapper.root.children[0] !== "string" | ||
? wrapper.root.children[0].props.style.animatedStyle.current.value.opacity | ||
: false, | ||
).toBe(initialValue); | ||
}); | ||
}); |
Oops, something went wrong.