diff --git a/.eslintrc b/.eslintrc index fe9c11d..ef52fb4 100644 --- a/.eslintrc +++ b/.eslintrc @@ -32,6 +32,11 @@ "ignoreComments": true } ], - "no-multiple-empty-lines": [2, {"max": 3}] + "no-multiple-empty-lines": [2, {"max": 3}], + "import/no-extraneous-dependencies": 0, + "react/jsx-filename-extension": 0, + "import/no-dynamic-require": 0, + "no-multi-assign": 0, + "o-undef": 0, } } diff --git a/.travis.yml b/.travis.yml index 64ff5de..932b332 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,22 +1,17 @@ language: node_js node_js: - - "4.0.0" - "6.0.0" - - "4" - "6" + - "8.9.1" + - "8" # values taken from react-native's package.json env: - - REACT_NATIVE_VERSION=0.38 REACT_VERSION=15.4.0 - - REACT_NATIVE_VERSION=0.39 REACT_VERSION=15.4.0-rc.4 - - REACT_NATIVE_VERSION=0.40 REACT_VERSION=15.4.1 - - REACT_NATIVE_VERSION=0.41 REACT_VERSION=15.4.0 - - REACT_NATIVE_VERSION=0.42 REACT_VERSION=15.4.1 - - REACT_NATIVE_VERSION=0.43 REACT_VERSION=16.0.0-alpha.6 + - REACT_NATIVE_VERSION=0.50 REACT_VERSION=16.0.0 +before_install: + - npm install react@~$REACT_VERSION react-dom@~$REACT_VERSION react-native@~$REACT_NATIVE_VERSION before_script: - - npm uninstall react-native react react-dom react-addons-test-utils - - npm install react@~$REACT_VERSION react-dom@~$REACT_VERSION react-addons-test-utils@~$REACT_VERSION react-native@~$REACT_NATIVE_VERSION - npm run build-haste diff --git a/README.md b/README.md index f84e2da..541723c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A fully mocked and test-friendly version of react native ## Requirements -- Node.js 4+ +- Node.js 6+ (dropping support for Node 4 as some dev dependencies don't support it) - The latest version of react-native __Note__: This library is designed to work with the most recent version of react-native. If you aren't using the most recent version, you will probably need to download an older version of this library, as the API is likely to be different, and the dependencies are likely to break. diff --git a/package.json b/package.json index dbab5ac..7685433 100644 --- a/package.json +++ b/package.json @@ -33,36 +33,38 @@ }, "homepage": "https://github.com/RealOrangeOne/react-native-mock#readme", "dependencies": { - "glob": "7.1.1", - "mockery": "2.0.0", + "glob": "7.1.2", + "mockery": "2.1.0", "perfy": "1.1.2", - "promise": "7.1.1", - "regenerator-runtime": "0.10.1", - "sinon": "1.17.7", + "promise": "8.0.1", + "regenerator-runtime": "0.11.0", + "sinon": "4.1.1", "underscore": "1.8.3" }, "devDependencies": { - "babel-cli": "6.9.0", - "chai": "3.5.0", - "chai-as-promised": "6.0.0", - "enzyme": "2.8.0", - "eslint": "2.10.2", - "eslint-config-airbnb": "9.0.1", - "eslint-plugin-import": "1.8.0", - "eslint-plugin-jsx-a11y": "1.2.2", - "eslint-plugin-react": "5.1.1", - "eslint-plugin-react-native": "1.0.2", - "jsdom": "9.9.1", - "mocha": "3.2.0", + "babel-cli": "6.26.0", + "chai": "4.1.2", + "chai-as-promised": "7.1.1", + "enzyme": "3.1.1", + "enzyme-adapter-react-16": "1.0.4", + "eslint": "4.10.0", + "eslint-config-airbnb": "16.1.0", + "eslint-plugin-import": "2.8.0", + "eslint-plugin-jsx-a11y": "6.0.2", + "eslint-plugin-react": "7.4.0", + "eslint-plugin-react-native": "3.1.0", + "jsdom": "11.3.0", + "mocha": "4.0.1", "mocha-assume": "1.0.0", - "nyc": "10.0.0", - "semver": "5.3.0", - "sinon-chai": "2.8.0" + "nyc": "11.3.0", + "semver": "5.4.1", + "sinon-chai": "2.14.0" }, "peerDependencies": { "babel-core": "*", "babel-preset-react-native": "*", - "react": ">=15.4.0", - "react-native": ">=0.38.0" + "react": ">=16.0.0", + "react-dom": ">=16.0.0", + "react-native": ">=0.50.0" } } diff --git a/scripts/test-helper.js b/scripts/test-helper.js index 478ee06..7830cb9 100644 --- a/scripts/test-helper.js +++ b/scripts/test-helper.js @@ -2,23 +2,28 @@ const chai = require('chai'); const sinonChai = require('sinon-chai'); const chaiAsPromised = require('chai-as-promised'); const jsdom = require('jsdom'); +const Enzyme = require('enzyme'); +const React16Adapter = require('enzyme-adapter-react-16'); + +Enzyme.configure({ adapter: new React16Adapter() }); chai.expect(); chai.use(sinonChai); chai.use(chaiAsPromised); // Jsdom document & window -const doc = jsdom.jsdom(''); -const win = doc.defaultView; +const { JSDOM } = jsdom; +const dom = new JSDOM(''); +const win = dom.window; // Add to global -global.document = doc; +global.document = win.document; global.window = win; // Add window keys to global window -Object.keys(window).forEach((key) => { +Object.keys(window).forEach((key) => { // eslint-disable-line no-undef if (!(key in global)) { - global[key] = window[key]; + global[key] = window[key]; // eslint-disable-line no-undef } }); diff --git a/src/NativeModules.js b/src/NativeModules.js index 1e9e436..39cc84f 100644 --- a/src/NativeModules.js +++ b/src/NativeModules.js @@ -1,5 +1,7 @@ import sinon from 'sinon'; +const ReactNativeVersion = require('react-native/Libraries/Core/ReactNativeVersion'); + module.exports = { AlertManager: { alertWithArgs: sinon.spy() @@ -63,11 +65,11 @@ module.exports = { }, IntentAndroid: { openURL: sinon.spy(), - canOpenURL: sinon.spy(url => new Promise((resolve) => resolve(true))) + canOpenURL: sinon.spy(url => new Promise(resolve => resolve(true))) }, LinkingManager: { openURL: sinon.spy(), - canOpenURL: sinon.spy(url => new Promise((resolve) => resolve(true))) + canOpenURL: sinon.spy(url => new Promise(resolve => resolve(true))) }, ModalFullscreenViewManager: {}, Networking: { @@ -145,7 +147,8 @@ module.exports = { osVersion: '10', interfaceIdiom: 'pad', isTesting: true, - version: '7' + version: '7', + reactNativeVersion: ReactNativeVersion.version }, AndroidConstants: { Version: '7', @@ -155,5 +158,15 @@ module.exports = { osVersion: '10', interfaceIdiom: 'pad', isTesting: true + }, + DeviceInfo: { + Dimensions: { + windowPhysicalPixels: { + fontScale: 2, + height: 1334, + scale: 2, + width: 750 + } + } } }; diff --git a/src/createMockComponent.js b/src/createMockComponent.js index 98719c1..f31117f 100644 --- a/src/createMockComponent.js +++ b/src/createMockComponent.js @@ -1,11 +1,11 @@ import React from 'react'; -export default name => { +export default (name) => { const RealComponent = require(name); const realComponentName = RealComponent.name === 'Component' ? name : RealComponent.name; const componentName = (RealComponent.displayName || realComponentName || name).replace(/^(RCT|RK)/, ''); - const Component = class extends RealComponent { // eslint-disable-line react/prefer-stateless-function + const Component = class extends RealComponent { // eslint-disable-line react/prefer-stateless-function render() { return React.createElement( componentName, diff --git a/src/haste.js b/src/haste.js index 52ca4ed..fc7e3ed 100644 --- a/src/haste.js +++ b/src/haste.js @@ -16,7 +16,7 @@ var PROJECT_NODE_MODULES = path.join(PROJECT_ROOT, 'node_modules'); var TIMER = 'time'; if (!fs.existsSync(PROJECT_NODE_MODULES)) { - PROJECT_NODE_MODULES = path.join(CWD, 'node_modules'); // For tests + PROJECT_NODE_MODULES = path.join(CWD, 'node_modules'); // For tests } perfy.start(TIMER); @@ -32,10 +32,10 @@ _.forEach(files, function (file) { var matches = providesRegex.exec(fs.readFileSync(file).toString()); if (matches && validName.test(matches[1])) { var component = matches[1]; - if (component.match(iosTest) && file.endsWith('.android.js')) { // Dont add IOS components if they end in android.js + if (component.match(iosTest) && file.endsWith('.android.js')) { // Dont add IOS components if they end in android.js return; } - if (component.match(androidTest) && file.endsWith('.ios.js')) { // Dont add Android components if they end in ios.js + if (component.match(androidTest) && file.endsWith('.ios.js')) { // Dont add Android components if they end in ios.js return; } data.hasteMap[component] = file.replace(PROJECT_NODE_MODULES + '/', ''); @@ -47,5 +47,5 @@ fs.writeFileSync(path.join(CWD, 'haste-map.json'), JSON.stringify(data, null, 2) var results = perfy.end(TIMER); if (process.env.NODE_ENV !== 'test') { - console.log(results.summary); // eslint-disable-line no-console + console.log(results.summary); // eslint-disable-line no-console } diff --git a/src/image-compiler.js b/src/image-compiler.js index 58a2b1f..7557275 100644 --- a/src/image-compiler.js +++ b/src/image-compiler.js @@ -4,6 +4,7 @@ */ const m = require('module'); + const originalLoader = m._load; m._load = function hookedLoader(request, parent, isMain) { diff --git a/src/mocks/AsyncStorage.js b/src/mocks/AsyncStorage.js index f576f49..b8e58e0 100644 --- a/src/mocks/AsyncStorage.js +++ b/src/mocks/AsyncStorage.js @@ -1,4 +1,4 @@ -const AsyncStorage = require('AsyncStorage'); // eslint-disable-line import/no-unresolved +const AsyncStorage = require('AsyncStorage'); // eslint-disable-line import/no-unresolved let _data = {}; diff --git a/src/mocks/ListView.js b/src/mocks/ListView.js index 9f1bce8..e2d96f5 100644 --- a/src/mocks/ListView.js +++ b/src/mocks/ListView.js @@ -11,7 +11,7 @@ /* eslint-disable react/prop-types */ const React = require('react'); -const ScrollView = require('ScrollView'); // eslint-disable-line import/no-unresolved +const ScrollView = require('ScrollView'); // eslint-disable-line import/no-unresolved const StaticRenderer = require('StaticRenderer'); // eslint-disable-line import/no-unresolved const View = require('View'); // eslint-disable-line import/no-unresolved @@ -24,23 +24,21 @@ class ListViewMock extends React.Component { const { dataSource, renderFooter, renderHeader } = this.props; const rows = [renderHeader && renderHeader()]; const allRowIDs = dataSource.rowIdentities; - for (let sectionIdx = 0; sectionIdx < allRowIDs.length; sectionIdx++) { + for (let sectionIdx = 0; sectionIdx < allRowIDs.length; sectionIdx += 1) { const sectionID = dataSource.sectionIdentities[sectionIdx]; const rowIDs = allRowIDs[sectionIdx]; - for (let rowIdx = 0; rowIdx < rowIDs.length; rowIdx++) { + for (let rowIdx = 0; rowIdx < rowIDs.length; rowIdx += 1) { const rowID = rowIDs[rowIdx]; - rows.push( - - ); + />); } } @@ -55,7 +53,7 @@ class ListViewMock extends React.Component { } ListViewMock.defaultProps = { - renderScrollComponent: (props) => + renderScrollComponent: props => }; ListViewMock.DataSource = require('ListViewDataSource'); // eslint-disable-line import/no-unresolved diff --git a/src/mocks/ListViewDataSource.js b/src/mocks/ListViewDataSource.js index c12cd6f..fcbda9b 100644 --- a/src/mocks/ListViewDataSource.js +++ b/src/mocks/ListViewDataSource.js @@ -1,11 +1,11 @@ -const DataSource = require('ListViewDataSource'); // eslint-disable-line import/no-unresolved +const DataSource = require('ListViewDataSource'); // eslint-disable-line import/no-unresolved DataSource.prototype.toJSON = function () { function ListViewDataSource(dataBlob) { this.items = 0; // Ensure this doesn't throw. try { - Object.keys(dataBlob).forEach(key => { + Object.keys(dataBlob).forEach((key) => { this.items += dataBlob[key] && ( dataBlob[key].length || dataBlob[key].size || 0 ); diff --git a/src/react-native-mock.js b/src/react-native-mock.js index f62ea21..6e3fb82 100644 --- a/src/react-native-mock.js +++ b/src/react-native-mock.js @@ -1,10 +1,11 @@ import mockery from 'mockery'; import _ from 'underscore'; +import React from 'react'; +import sinon from 'sinon'; + import defineGlobalProperty from './defineGlobalProperty'; import createMockComponent, { MOCK_COMPONENTS } from './createMockComponent'; import mockNativeModules from './NativeModules'; -import React from 'react'; -import sinon from 'sinon'; // Setup babel to build react-native source @@ -33,7 +34,7 @@ mockery.registerMock('ensureComponentIsNative', () => true); mockery.registerMock('requireNativeComponent', sinon.spy(viewName => props => React.createElement( viewName, props, - props.children // eslint-disable-line react/prop-types + props.children // eslint-disable-line react/prop-types ))); mockery.registerMock('ErrorUtils', require('./mocks/ErrorUtils')); diff --git a/tests/image-compiler.test.js b/tests/image-compiler.test.js index db385e8..c1ed71a 100644 --- a/tests/image-compiler.test.js +++ b/tests/image-compiler.test.js @@ -3,7 +3,7 @@ import { expect } from 'chai'; describe('Image Compiler', function () { it('should require a jpg image', function () { - expect(require('foo.jpg')).to.deep.equal({ uri: 'foo.jpg' }); // eslint-disable-line import/no-unresolved + expect(require('foo.jpg')).to.deep.equal({ uri: 'foo.jpg' }); // eslint-disable-line import/no-unresolved }); it('should require a jpeg image', function () { diff --git a/tests/integration/apis/AlertIOS.test.js b/tests/integration/apis/AlertIOS.test.js index cdd4f8e..402a56f 100644 --- a/tests/integration/apis/AlertIOS.test.js +++ b/tests/integration/apis/AlertIOS.test.js @@ -36,7 +36,7 @@ describe('AlertIOS', () => { }, { text: 'OK', - onPress: password => {} + onPress: (password) => {} } ], 'secure-text' diff --git a/tests/integration/apis/BackAndroid.test.js b/tests/integration/apis/BackAndroid.test.js index 7a9645c..ee5b048 100644 --- a/tests/integration/apis/BackAndroid.test.js +++ b/tests/integration/apis/BackAndroid.test.js @@ -1,20 +1,11 @@ import { expect } from 'chai'; -import sinon from 'sinon'; describe('BackAndroid', () => { const { BackAndroid } = require('react-native'); it('should bind events', function () { expect(BackAndroid.addEventListener).to.be.a('function'); - expect(BackAndroid.addEventListener().remove).to.be.a('function'); expect(BackAndroid.removeEventListener).to.be.a('function'); expect(BackAndroid.exitApp).to.be.a('function'); }); - - it('should remove', function () { - sinon.stub(BackAndroid, 'removeEventListener'); - BackAndroid.addEventListener().remove(); - expect(BackAndroid.removeEventListener).to.have.been.calledOnce; - BackAndroid.removeEventListener.restore(); - }); }); diff --git a/tests/integration/apis/BackHandler.test.js b/tests/integration/apis/BackHandler.test.js new file mode 100644 index 0000000..a201bd6 --- /dev/null +++ b/tests/integration/apis/BackHandler.test.js @@ -0,0 +1,11 @@ +import { expect } from 'chai'; + +describe('BackHandler', () => { + const { BackHandler } = require('react-native'); + + it('should bind events', function () { + expect(BackHandler.addEventListener).to.be.a('function'); + expect(BackHandler.removeEventListener).to.be.a('function'); + expect(BackHandler.exitApp).to.be.a('function'); + }); +}); diff --git a/tests/integration/apis/Dimensions.test.js b/tests/integration/apis/Dimensions.test.js index bf6f27b..83b4e89 100644 --- a/tests/integration/apis/Dimensions.test.js +++ b/tests/integration/apis/Dimensions.test.js @@ -7,9 +7,9 @@ describe('Dimensions', () => { it('should get dimensions', function () { expect(Dimensions.get('window')).to.deep.equal({ fontScale: 2, - height: 1334, + height: 667, scale: 2, - width: 750 + width: 375 }); }); diff --git a/tests/integration/apis/Easing.test.js b/tests/integration/apis/Easing.test.js index 1c1e6c0..1af5102 100644 --- a/tests/integration/apis/Easing.test.js +++ b/tests/integration/apis/Easing.test.js @@ -14,7 +14,7 @@ import { expect } from 'chai'; describe('Easing', () => { const { Easing } = require('react-native'); - it('should have all functions', function () { + it('should have all functions', () => { expect(Easing.step0).to.be.a('function'); expect(Easing.step1).to.be.a('function'); expect(Easing.linear).to.be.a('function'); @@ -34,8 +34,8 @@ describe('Easing', () => { expect(Easing.inOut).to.be.a('function'); }); - describe('linear', function () { - it('should work', function () { + describe('linear', () => { + it('should work', () => { const easing = Easing.linear; expect(easing(0)).to.equal(0); @@ -44,7 +44,7 @@ describe('Easing', () => { expect(easing(1)).to.equal(1); }); - it('should work with ease in', function () { + it('should work with ease in', () => { const easing = Easing.in(Easing.linear); expect(easing(0)).to.equal(0); expect(easing(0.5)).to.equal(0.5); @@ -52,7 +52,7 @@ describe('Easing', () => { expect(easing(1)).to.equal(1); }); - it('should work with ease out', function () { + it('should work with ease out', () => { const easing = Easing.out(Easing.linear); expect(easing(0)).to.equal(0); expect(easing(0.5)).to.equal(0.5); @@ -61,7 +61,7 @@ describe('Easing', () => { }); }); - describe('quad', function () { + describe('quad', () => { it('should work with ease in', () => { function easeInQuad(t) { return t * t; @@ -87,7 +87,7 @@ describe('Easing', () => { if (t < 1) { return 0.5 * t * t; } - return -((t - 1) * (t - 3) - 1) / 2; + return -(((t - 1) * (t - 3)) - 1) / 2; } const easing = Easing.inOut(Easing.quad); for (let t = -0.5; t < 1.5; t += 0.1) { @@ -104,39 +104,39 @@ describe('Easing', () => { } }); - describe('samples', function () { + describe('samples', () => { function sampleEasingFunction(easing) { const DURATION = 300; - const tickCount = Math.round(DURATION * 60 / 1000); + const tickCount = Math.round((DURATION * 60) / 1000); const samples = []; - for (let i = 0; i <= tickCount; i++) { + for (let i = 0; i <= tickCount; i += 1) { samples.push(easing(i / tickCount)); } return samples; } const SAMPLES = { - in_quad: [0, 0.0030864197530864196, 0.012345679012345678, 0.027777777777777776, 0.04938271604938271, 0.0771604938271605, 0.1111111111111111, 0.15123456790123457, 0.19753086419753085, 0.25, 0.308641975308642, 0.37345679012345684, 0.4444444444444444, 0.5216049382716049, 0.6049382716049383, 0.6944444444444445, 0.7901234567901234, 0.8919753086419753, 1], // eslint-disable-line max-len - out_quad: [0, 0.10802469135802469, 0.20987654320987653, 0.3055555555555555, 0.3950617283950617, 0.47839506172839513, 0.5555555555555556, 0.6265432098765432, 0.691358024691358, 0.75, 0.8024691358024691, 0.8487654320987654, 0.888888888888889, 0.9228395061728394, 0.9506172839506174, 0.9722222222222221, 0.9876543209876543, 0.9969135802469136, 1], // eslint-disable-line max-len - inOut_quad: [0, 0.006172839506172839, 0.024691358024691357, 0.05555555555555555, 0.09876543209876543, 0.154320987654321, 0.2222222222222222, 0.30246913580246915, 0.3950617283950617, 0.5, 0.6049382716049383, 0.697530864197531, 0.7777777777777777, 0.845679012345679, 0.9012345679012346, 0.9444444444444444, 0.9753086419753086, 0.9938271604938271, 1], // eslint-disable-line max-len - in_cubic: [0, 0.00017146776406035664, 0.0013717421124828531, 0.004629629629629629, 0.010973936899862825, 0.021433470507544586, 0.037037037037037035, 0.05881344307270234, 0.0877914951989026, 0.125, 0.1714677640603567, 0.22822359396433475, 0.2962962962962963, 0.37671467764060357, 0.4705075445816187, 0.5787037037037038, 0.7023319615912208, 0.8424211248285322, 1], // eslint-disable-line max-len - out_cubic: [0, 0.15757887517146785, 0.2976680384087792, 0.42129629629629617, 0.5294924554183813, 0.6232853223593964, 0.7037037037037036, 0.7717764060356652, 0.8285322359396433, 0.875, 0.9122085048010974, 0.9411865569272977, 0.9629629629629629, 0.9785665294924554, 0.9890260631001372, 0.9953703703703703, 0.9986282578875172, 0.9998285322359396, 1], // eslint-disable-line max-len - inOut_cubic: [0, 0.0006858710562414266, 0.0054869684499314125, 0.018518518518518517, 0.0438957475994513, 0.08573388203017834, 0.14814814814814814, 0.23525377229080935, 0.3511659807956104, 0.5, 0.6488340192043895, 0.7647462277091908, 0.8518518518518519, 0.9142661179698217, 0.9561042524005487, 0.9814814814814815, 0.9945130315500685, 0.9993141289437586, 1], // eslint-disable-line max-len - in_sin: [0, 0.003805301908254455, 0.01519224698779198, 0.03407417371093169, 0.06030737921409157, 0.09369221296335006, 0.1339745962155613, 0.1808479557110082, 0.233955556881022, 0.2928932188134524, 0.35721239031346064, 0.42642356364895384, 0.4999999999999999, 0.5773817382593005, 0.6579798566743311, 0.7411809548974793, 0.8263518223330696, 0.9128442572523416, 0.9999999999999999], // eslint-disable-line max-len - out_sin: [0, 0.08715574274765817, 0.17364817766693033, 0.25881904510252074, 0.3420201433256687, 0.42261826174069944, 0.49999999999999994, 0.573576436351046, 0.6427876096865393, 0.7071067811865475, 0.766044443118978, 0.8191520442889918, 0.8660254037844386, 0.9063077870366499, 0.9396926207859083, 0.9659258262890683, 0.984807753012208, 0.9961946980917455, 1], // eslint-disable-line max-len - inOut_sin: [0, 0.00759612349389599, 0.030153689607045786, 0.06698729810778065, 0.116977778440511, 0.17860619515673032, 0.24999999999999994, 0.32898992833716556, 0.4131759111665348, 0.49999999999999994, 0.5868240888334652, 0.6710100716628343, 0.7499999999999999, 0.8213938048432696, 0.883022221559489, 0.9330127018922194, 0.9698463103929542, 0.9924038765061041, 1], // eslint-disable-line max-len - in_exp: [0, 0.0014352875901128893, 0.002109491677524035, 0.0031003926796253885, 0.004556754060844206, 0.006697218616039631, 0.009843133202303688, 0.014466792379488908, 0.021262343752724643, 0.03125, 0.045929202883612456, 0.06750373368076916, 0.09921256574801243, 0.1458161299470146, 0.2143109957132682, 0.31498026247371835, 0.46293735614364506, 0.6803950000871883, 1], // eslint-disable-line max-len - out_exp: [0, 0.31960499991281155, 0.5370626438563548, 0.6850197375262816, 0.7856890042867318, 0.8541838700529854, 0.9007874342519875, 0.9324962663192309, 0.9540707971163875, 0.96875, 0.9787376562472754, 0.9855332076205111, 0.9901568667976963, 0.9933027813839603, 0.9954432459391558, 0.9968996073203746, 0.9978905083224759, 0.9985647124098871, 1], // eslint-disable-line max-len - inOut_exp: [0, 0.0010547458387620175, 0.002278377030422103, 0.004921566601151844, 0.010631171876362321, 0.022964601441806228, 0.049606282874006216, 0.1071554978566341, 0.23146867807182253, 0.5, 0.7685313219281775, 0.892844502143366, 0.9503937171259937, 0.9770353985581938, 0.9893688281236377, 0.9950784333988482, 0.9977216229695779, 0.998945254161238, 1], // eslint-disable-line max-len - in_circle: [0, 0.0015444024660317135, 0.006192010000093506, 0.013986702816730645, 0.025003956956430873, 0.03935464078941209, 0.057190958417936644, 0.07871533601238889, 0.10419358352238339, 0.1339745962155614, 0.1685205807169019, 0.20845517506805522, 0.2546440075000701, 0.3083389112228482, 0.37146063894529113, 0.4472292016074334, 0.5418771527091488, 0.6713289009389102, 1], // eslint-disable-line max-len - out_circle: [0, 0.3286710990610898, 0.45812284729085123, 0.5527707983925666, 0.6285393610547089, 0.6916610887771518, 0.7453559924999298, 0.7915448249319448, 0.8314794192830981, 0.8660254037844386, 0.8958064164776166, 0.9212846639876111, 0.9428090415820634, 0.9606453592105879, 0.9749960430435691, 0.9860132971832694, 0.9938079899999065, 0.9984555975339683, 1], // eslint-disable-line max-len - inOut_circle: [0, 0.003096005000046753, 0.012501978478215436, 0.028595479208968322, 0.052096791761191696, 0.08426029035845095, 0.12732200375003505, 0.18573031947264557, 0.2709385763545744, 0.5, 0.7290614236454256, 0.8142696805273546, 0.8726779962499649, 0.915739709641549, 0.9479032082388084, 0.9714045207910317, 0.9874980215217846, 0.9969039949999532, 1], // eslint-disable-line max-len - in_back_: [0, -0.004788556241426612, -0.017301289437585736, -0.0347587962962963, -0.05438167352537723, -0.07339051783264748, -0.08900592592592595, -0.09844849451303156, -0.0989388203017833, -0.08769750000000004, -0.06194513031550073, -0.018902307956104283, 0.044210370370370254, 0.13017230795610413, 0.2417629080932785, 0.3817615740740742, 0.5529477091906719, 0.7581007167352535, 0.9999999999999998], // eslint-disable-line max-len - out_back_: [2.220446049250313e-16, 0.24189928326474652, 0.44705229080932807, 0.6182384259259258, 0.7582370919067215, 0.8698276920438959, 0.9557896296296297, 1.0189023079561044, 1.0619451303155008, 1.0876975, 1.0989388203017834, 1.0984484945130315, 1.089005925925926, 1.0733905178326475, 1.0543816735253773, 1.0347587962962963, 1.0173012894375857, 1.0047885562414267, 1] // eslint-disable-line max-len + in_quad: [0, 0.0030864197530864196, 0.012345679012345678, 0.027777777777777776, 0.04938271604938271, 0.0771604938271605, 0.1111111111111111, 0.15123456790123457, 0.19753086419753085, 0.25, 0.308641975308642, 0.37345679012345684, 0.4444444444444444, 0.5216049382716049, 0.6049382716049383, 0.6944444444444445, 0.7901234567901234, 0.8919753086419753, 1], // eslint-disable-line max-len + out_quad: [0, 0.10802469135802469, 0.20987654320987653, 0.3055555555555555, 0.3950617283950617, 0.47839506172839513, 0.5555555555555556, 0.6265432098765432, 0.691358024691358, 0.75, 0.8024691358024691, 0.8487654320987654, 0.888888888888889, 0.9228395061728394, 0.9506172839506174, 0.9722222222222221, 0.9876543209876543, 0.9969135802469136, 1], // eslint-disable-line max-len + inOut_quad: [0, 0.006172839506172839, 0.024691358024691357, 0.05555555555555555, 0.09876543209876543, 0.154320987654321, 0.2222222222222222, 0.30246913580246915, 0.3950617283950617, 0.5, 0.6049382716049383, 0.697530864197531, 0.7777777777777777, 0.845679012345679, 0.9012345679012346, 0.9444444444444444, 0.9753086419753086, 0.9938271604938271, 1], // eslint-disable-line max-len + in_cubic: [0, 0.00017146776406035664, 0.0013717421124828531, 0.004629629629629629, 0.010973936899862825, 0.021433470507544586, 0.037037037037037035, 0.05881344307270234, 0.0877914951989026, 0.125, 0.1714677640603567, 0.22822359396433475, 0.2962962962962963, 0.37671467764060357, 0.4705075445816187, 0.5787037037037038, 0.7023319615912208, 0.8424211248285322, 1], // eslint-disable-line max-len + out_cubic: [0, 0.15757887517146785, 0.2976680384087792, 0.42129629629629617, 0.5294924554183813, 0.6232853223593964, 0.7037037037037036, 0.7717764060356652, 0.8285322359396433, 0.875, 0.9122085048010974, 0.9411865569272977, 0.9629629629629629, 0.9785665294924554, 0.9890260631001372, 0.9953703703703703, 0.9986282578875172, 0.9998285322359396, 1], // eslint-disable-line max-len + inOut_cubic: [0, 0.0006858710562414266, 0.0054869684499314125, 0.018518518518518517, 0.0438957475994513, 0.08573388203017834, 0.14814814814814814, 0.23525377229080935, 0.3511659807956104, 0.5, 0.6488340192043895, 0.7647462277091908, 0.8518518518518519, 0.9142661179698217, 0.9561042524005487, 0.9814814814814815, 0.9945130315500685, 0.9993141289437586, 1], // eslint-disable-line max-len + in_sin: [0, 0.003805301908254455, 0.01519224698779198, 0.03407417371093169, 0.06030737921409157, 0.09369221296335006, 0.1339745962155613, 0.1808479557110082, 0.233955556881022, 0.2928932188134524, 0.35721239031346064, 0.42642356364895384, 0.4999999999999999, 0.5773817382593005, 0.6579798566743311, 0.7411809548974793, 0.8263518223330696, 0.9128442572523416, 0.9999999999999999], // eslint-disable-line max-len + out_sin: [0, 0.08715574274765817, 0.17364817766693033, 0.25881904510252074, 0.3420201433256687, 0.42261826174069944, 0.49999999999999994, 0.573576436351046, 0.6427876096865393, 0.7071067811865475, 0.766044443118978, 0.8191520442889918, 0.8660254037844386, 0.9063077870366499, 0.9396926207859083, 0.9659258262890683, 0.984807753012208, 0.9961946980917455, 1], // eslint-disable-line max-len + inOut_sin: [0, 0.00759612349389599, 0.030153689607045786, 0.06698729810778065, 0.116977778440511, 0.17860619515673032, 0.24999999999999994, 0.32898992833716556, 0.4131759111665348, 0.49999999999999994, 0.5868240888334652, 0.6710100716628343, 0.7499999999999999, 0.8213938048432696, 0.883022221559489, 0.9330127018922194, 0.9698463103929542, 0.9924038765061041, 1], // eslint-disable-line max-len + in_exp: [0, 0.0014352875901128893, 0.002109491677524035, 0.0031003926796253885, 0.004556754060844206, 0.006697218616039631, 0.009843133202303688, 0.014466792379488908, 0.021262343752724643, 0.03125, 0.045929202883612456, 0.06750373368076916, 0.09921256574801243, 0.1458161299470146, 0.2143109957132682, 0.31498026247371835, 0.46293735614364506, 0.6803950000871883, 1], // eslint-disable-line max-len + out_exp: [0, 0.31960499991281155, 0.5370626438563548, 0.6850197375262816, 0.7856890042867318, 0.8541838700529854, 0.9007874342519875, 0.9324962663192309, 0.9540707971163875, 0.96875, 0.9787376562472754, 0.9855332076205111, 0.9901568667976963, 0.9933027813839603, 0.9954432459391558, 0.9968996073203746, 0.9978905083224759, 0.9985647124098871, 1], // eslint-disable-line max-len + inOut_exp: [0, 0.0010547458387620175, 0.002278377030422103, 0.004921566601151844, 0.010631171876362321, 0.022964601441806228, 0.049606282874006216, 0.1071554978566341, 0.23146867807182253, 0.5, 0.7685313219281775, 0.892844502143366, 0.9503937171259937, 0.9770353985581938, 0.9893688281236377, 0.9950784333988482, 0.9977216229695779, 0.998945254161238, 1], // eslint-disable-line max-len + in_circle: [0, 0.0015444024660317135, 0.006192010000093506, 0.013986702816730645, 0.025003956956430873, 0.03935464078941209, 0.057190958417936644, 0.07871533601238889, 0.10419358352238339, 0.1339745962155614, 0.1685205807169019, 0.20845517506805522, 0.2546440075000701, 0.3083389112228482, 0.37146063894529113, 0.4472292016074334, 0.5418771527091488, 0.6713289009389102, 1], // eslint-disable-line max-len + out_circle: [0, 0.3286710990610898, 0.45812284729085123, 0.5527707983925666, 0.6285393610547089, 0.6916610887771518, 0.7453559924999298, 0.7915448249319448, 0.8314794192830981, 0.8660254037844386, 0.8958064164776166, 0.9212846639876111, 0.9428090415820634, 0.9606453592105879, 0.9749960430435691, 0.9860132971832694, 0.9938079899999065, 0.9984555975339683, 1], // eslint-disable-line max-len + inOut_circle: [0, 0.003096005000046753, 0.012501978478215436, 0.028595479208968322, 0.052096791761191696, 0.08426029035845095, 0.12732200375003505, 0.18573031947264557, 0.2709385763545744, 0.5, 0.7290614236454256, 0.8142696805273546, 0.8726779962499649, 0.915739709641549, 0.9479032082388084, 0.9714045207910317, 0.9874980215217846, 0.9969039949999532, 1], // eslint-disable-line max-len + in_back_: [0, -0.004788556241426612, -0.017301289437585736, -0.0347587962962963, -0.05438167352537723, -0.07339051783264748, -0.08900592592592595, -0.09844849451303156, -0.0989388203017833, -0.08769750000000004, -0.06194513031550073, -0.018902307956104283, 0.044210370370370254, 0.13017230795610413, 0.2417629080932785, 0.3817615740740742, 0.5529477091906719, 0.7581007167352535, 0.9999999999999998], // eslint-disable-line max-len + out_back_: [2.220446049250313e-16, 0.24189928326474652, 0.44705229080932807, 0.6182384259259258, 0.7582370919067215, 0.8698276920438959, 0.9557896296296297, 1.0189023079561044, 1.0619451303155008, 1.0876975, 1.0989388203017834, 1.0984484945130315, 1.089005925925926, 1.0733905178326475, 1.0543816735253773, 1.0347587962962963, 1.0173012894375857, 1.0047885562414267, 1] // eslint-disable-line max-len }; - Object.keys(SAMPLES).forEach(function (type) { - it('should ease ' + type, function () { + Object.keys(SAMPLES).forEach((type) => { + it(`should ease ${type}`, () => { const [modeName, easingName, isFunction] = type.split('_'); let easing = Easing[easingName]; if (isFunction !== undefined) { diff --git a/tests/integration/apis/StyleSheet.test.js b/tests/integration/apis/StyleSheet.test.js index 3a5dcf1..94be83e 100644 --- a/tests/integration/apis/StyleSheet.test.js +++ b/tests/integration/apis/StyleSheet.test.js @@ -46,9 +46,7 @@ describe('StyleSheet', () => { }); it('should flatten with nested array', () => { - const result = StyleSheet.flatten( - [styles.listItem, [styles.headerItem, styles.selectedListItem]] - ); + const result = StyleSheet.flatten([styles.listItem, [styles.headerItem, styles.selectedListItem]]); expect(result).to.deep.equal({ flex: 1, fontSize: 16, diff --git a/tests/integration/components.test.js b/tests/integration/components.test.js index c90e0e3..4acd618 100644 --- a/tests/integration/components.test.js +++ b/tests/integration/components.test.js @@ -1,8 +1,8 @@ import React from 'react'; // eslint-disable-line no-unused-vars import { shallow } from 'enzyme'; import { expect } from 'chai'; -import { buildComponentHTML } from '../test-utils'; import sinon from 'sinon'; +import { buildComponentHTML } from '../test-utils'; const COMPONENTS = [ 'Image', @@ -23,7 +23,7 @@ describe('Components', function () { it(`should render ${component}`, function () { const Component = ReactNative[component]; const instance = shallow(); - expect(instance.html()).to.equal(buildComponentHTML(component)); + expect(instance.html()).to.include(`<${component}`); }); }); @@ -55,7 +55,6 @@ describe('Components', function () { it('should have DrawerLayoutAndroid with static properties for the positions', () => { const { DrawerLayoutAndroid } = ReactNative; - expect(DrawerLayoutAndroid.positions).to.be.an.object; expect(DrawerLayoutAndroid.positions).to.deep.equal({ Left: 'LEFT', Right: 'RIGHT' @@ -75,16 +74,7 @@ describe('Components', function () { it('should render KeyboardAvoidingView', function () { const { KeyboardAvoidingView } = ReactNative; const instance = shallow(); - expect(instance.html()).to.equal(buildComponentHTML('View')); - }); - - it('should render Navigator', function () { - const { Navigator, Text } = ReactNative; - const renderScene = sinon.spy((route, navigator) => Hello!); - const instance = shallow(); - expect(instance.html()).to.include('View'); - expect(instance.html()).to.include('Hello!'); - expect(renderScene).to.have.been.called; + expect(instance.html()).to.include('); expect(instance.html()).to.include('); - expect(instance.html()).to.equal(buildComponentHTML('Text')); + expect(instance.html()).to.include(').html()).to.equal(shallow().html()); }); diff --git a/tests/native-modules.test.js b/tests/native-modules.test.js index e554f87..0e7a6dd 100644 --- a/tests/native-modules.test.js +++ b/tests/native-modules.test.js @@ -1,12 +1,14 @@ import { expect } from 'chai'; -const NativeModules = require('../src/NativeModules'); import sinon from 'sinon'; + import { expectSpy } from './test-utils'; +const NativeModules = require('../src/NativeModules'); + describe('Native Modules', function () { it('Should be defined', function () { expect(NativeModules).to.be.an('object'); - expect(Object.keys(require('NativeModules'))).to.deep.equal(Object.keys(NativeModules)); // eslint-disable-line import/no-unresolved + expect(Object.keys(require('NativeModules'))).to.deep.equal(Object.keys(NativeModules)); // eslint-disable-line import/no-unresolved }); it('should be requirable', function () { diff --git a/tests/no-import.test.js b/tests/no-import.test.js index 62987cd..dcf9418 100644 --- a/tests/no-import.test.js +++ b/tests/no-import.test.js @@ -8,7 +8,7 @@ describe('React-Native-Mock import', function () { }); it('should happen when requiring react-native-mock', function () { - const main = require('../package.json').main; + const { main } = require('../package.json'); expect(() => require(path.join('..', main))).to.throw; }); }); diff --git a/tests/test-utils.js b/tests/test-utils.js index e51a116..cf20cf6 100644 --- a/tests/test-utils.js +++ b/tests/test-utils.js @@ -2,12 +2,10 @@ import { expect } from 'chai'; import sinon from 'sinon'; import semver from 'semver'; -export const buildComponentHTML = (componentName) => `<${componentName}>`; +export const buildComponentHTML = componentName => `<${componentName}>`; export const expectSpy = function isSpy(spy) { - expect(spy).to.contain.all.keys( - Object.keys(sinon.spy()) - ); + expect(spy).to.contain.all.keys(Object.keys(sinon.spy())); expect(spy.id).to.contain('spy'); expect(spy.callCount).to.be.a('number'); expect(spy.called).to.be.a('boolean');