Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemKosiakevych committed Dec 27, 2016
1 parent 93414f9 commit 55218bc
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["react-native"],
"ignore": false
}
39 changes: 39 additions & 0 deletions Tests/Setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import mockery from 'mockery';
import m from 'module';

// inject __DEV__ as it is not available when running through the tests
global.__DEV__ = true;

// We enable mockery and leave it on.
mockery.enable();

// Silence the warnings when *real* modules load... this is a change from
// the norm. We want to opt-in instead of opt-out because not everything
// will be mocked.
mockery.warnOnUnregistered(false);

// Mock any libs that get called in here
// I'm looking at you react-native-router-flux, reactotron etc!
mockery.registerMock('reactotron-react-native', {});
mockery.registerMock('reactotron-redux', {});
mockery.registerMock('reactotron-apisauce', {});
mockery.registerMock('react-native-animatable', { View: 'Animatable.View' });
mockery.registerMock('react-native-vector-icons/Ionicons', {});

// mock i18n as it uses react native stufff
mockery.registerMock('react-native-i18n', {
t: key => key,
});

mockery.registerMock('react-native-router-flux', {});


// Mock all images for React Native
const originalLoader = m._load;
m._load = (request, parent, isMain) => {
if (request.match(/.jpeg|.jpg|.png|.gif$/)) {
return { uri: request };
}

return originalLoader(request, parent, isMain);
};
27 changes: 27 additions & 0 deletions Tests/WheelPicker.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';

import test from 'ava';
import { shallow } from 'enzyme';
import WheelPicker from '../WheelPicker';
const wrapper = shallow(<WheelPicker />);

test('component exists', (t) => {
t.is(wrapper.length, 1); // exists
});

test('component structure', (t) => {
t.is(wrapper.name(), 'WheelPicker'); // the right root component
t.is(wrapper.children().length, 0); // has 1 child
});

test('data', (t) => {
const data = [1, 2, 3];
const wrapperPress = shallow(<WheelPicker isCyclic={false} isCurved isAtmospheric visibleItemCount={4} backgroundColor={'black'} data={data} />);

t.is(wrapperPress.prop('data').length, 3);
t.is(wrapperPress.prop('isCurved'), true);
t.is(wrapperPress.prop('isAtmospheric'), true);
t.is(wrapperPress.prop('isCyclic'), false);
t.is(wrapperPress.prop('visibleItemCount'), 4);
t.is(wrapperPress.prop('backgroundColor'), 'black');
});
19 changes: 13 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-wheel-picker-android",
"version": "0.1.5",
"version": "0.1.6",
"description": "Simple Wheel Picker for Android to use with react-native",
"main": "index.js",
"repository": {
Expand All @@ -25,18 +25,25 @@
"lint": "eslint .",
"test": "ava"
},
"ava": {
"babel": "inherit",
"files": [ "Tests/**/*.js", "!Tests/Setup.js" ],
"require": [
"babel-register",
"babel-polyfill",
"react-native-mock/mock",
"./Tests/Setup"
]
},
"devDependencies": {
"ava": "^0.17.0",
"react": "~15.3.0",
"react-native": "^0.34.0",
"react-dom": "^15.3.1",
"react-addons-test-utils": "^15.3.1",
"eslint": "^3.12.2",
"eslint-config-airbnb": "^13.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.8.0",
"pre-commit": "^1.2.2"
"pre-commit": "^1.2.2",
"react-native-mock": "^0.2.9"
},
"pre-commit": [
"test"
Expand Down
8 changes: 0 additions & 8 deletions test/WheelPicker.test.js

This file was deleted.

0 comments on commit 55218bc

Please sign in to comment.