This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
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
andy
committed
Oct 29, 2019
1 parent
109ee06
commit 01cde7d
Showing
9 changed files
with
395 additions
and
24 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
presets: ['module:metro-react-native-babel-preset'], | ||
}; |
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
This file was deleted.
Oops, something went wrong.
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 @@ | ||
import React from 'react'; | ||
import { render } from './test-utils'; | ||
import { Pager } from '../src'; | ||
import { Text } from 'react-native'; | ||
|
||
test('render()', () => { | ||
const { debug } = render( | ||
<Pager style={{ width: 200, height: 200 }}> | ||
<Text>1</Text> | ||
<Text>2</Text> | ||
</Pager> | ||
); | ||
|
||
debug(); | ||
}); |
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,50 @@ | ||
jest.mock('react-native-reanimated', () => { | ||
const mock = require('react-native-reanimated/mock'); | ||
mock.default.Value = function() { | ||
return { | ||
setValue: function() {}, | ||
}; | ||
}; | ||
|
||
mock.default.proc = function() { | ||
return function() {}; | ||
}; | ||
|
||
return mock; | ||
}); | ||
|
||
jest.mock('react-native-gesture-handler', () => { | ||
const View = require('react-native/Libraries/Components/View/View'); | ||
return { | ||
Swipeable: View, | ||
DrawerLayout: View, | ||
State: {}, | ||
ScrollView: View, | ||
Slider: View, | ||
Switch: View, | ||
TextInput: View, | ||
ToolbarAndroid: View, | ||
ViewPagerAndroid: View, | ||
DrawerLayoutAndroid: View, | ||
WebView: View, | ||
NativeViewGestureHandler: View, | ||
TapGestureHandler: View, | ||
FlingGestureHandler: View, | ||
ForceTouchGestureHandler: View, | ||
LongPressGestureHandler: View, | ||
PanGestureHandler: View, | ||
PinchGestureHandler: View, | ||
RotationGestureHandler: View, | ||
/* Buttons */ | ||
RawButton: View, | ||
BaseButton: View, | ||
RectButton: View, | ||
BorderlessButton: View, | ||
/* Other */ | ||
FlatList: View, | ||
gestureHandlerRootHOC: jest.fn(), | ||
Directions: {}, | ||
}; | ||
}); | ||
|
||
import '@testing-library/jest-native/extend-expect'; |
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,78 @@ | ||
import { render, prettyPrint } from '@testing-library/react-native'; | ||
import format from 'pretty-format'; | ||
|
||
const { ReactElement, ReactTestComponent } = format.plugins; | ||
|
||
function createFormatter(propsToRemove) { | ||
const plugin = { | ||
test(val: any) { | ||
return val.props !== undefined; | ||
}, | ||
serialize( | ||
element: any, | ||
config: any, | ||
indentation: any, | ||
depth: any, | ||
refs: any, | ||
printer: any | ||
) { | ||
Object.keys(element.props).map(prop => { | ||
if (propsToRemove.includes(prop)) { | ||
delete element.props[prop]; | ||
} | ||
}); | ||
|
||
if (ReactTestComponent.test(element)) { | ||
return ReactTestComponent.serialize( | ||
element, | ||
config, | ||
indentation, | ||
depth, | ||
refs, | ||
printer | ||
); | ||
} | ||
|
||
return ReactElement.serialize( | ||
element, | ||
config, | ||
indentation, | ||
depth, | ||
refs, | ||
printer | ||
); | ||
}, | ||
}; | ||
|
||
return plugin; | ||
} | ||
|
||
const removeStyleProp = createFormatter([ | ||
'style', | ||
'pointerEvents', | ||
'collapsable', | ||
]); | ||
|
||
const defaultPlugins = [removeStyleProp, ReactTestComponent, ReactElement]; | ||
|
||
const customRender = (ui: any, options?: any) => { | ||
const utils = render(ui, { ...options }); | ||
|
||
function removeStylesFromDebug() { | ||
return console.log( | ||
// @ts-ignore | ||
prettyPrint(utils.baseElement, undefined, { plugins: defaultPlugins }) | ||
); | ||
} | ||
|
||
return { | ||
...utils, | ||
debug: removeStylesFromDebug, | ||
}; | ||
}; | ||
|
||
// re-export everything | ||
export * from '@testing-library/react-native'; | ||
|
||
// override render method | ||
export { customRender as render }; |
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
Oops, something went wrong.