Skip to content

Commit a9084f2

Browse files
committed
Merge branch 'master' into ticketea-android-support
2 parents 0f8c330 + 12091d7 commit a9084f2

File tree

7 files changed

+45
-24
lines changed

7 files changed

+45
-24
lines changed

lib/__mocks__/ListView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = jest.genMockFromModule('./View')
1+
module.exports = require.requireActual('./react-native').ListView;

lib/__mocks__/View.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

lib/__mocks__/react-native.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
var React = require.requireActual('react/dist/react-with-addons')
22

3+
function makeMockComponentClass(displayName) {
4+
return React.createClass({
5+
displayName,
6+
render() {
7+
return this.props.children
8+
},
9+
})
10+
}
11+
312
var ReactNative = {
413
...React,
5-
ActivityIndicatorIOS: jest.genMockFromModule('./View'),
6-
ListView: jest.genMockFromModule('./View'),
7-
View: jest.genMockFromModule('./View'),
8-
Text: jest.genMockFromModule('./View'),
14+
ActivityIndicatorIOS: makeMockComponentClass('ActivityIndicatorIOS'),
15+
ListView: makeMockComponentClass('ListView'),
16+
View: makeMockComponentClass('View'),
17+
Text: makeMockComponentClass('Text'),
918
StyleSheet: {
1019
create: (ss) => ss,
1120
},

lib/__tests__/RefreshingIndicator-test.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ jest.dontMock('../RefreshingIndicator')
22

33
describe('RefreshingIndicator', function() {
44
let React
5+
let ReactNative
6+
let ShallowTestUtils
57
let RefreshingIndicator
68
let description
79

810
beforeEach(function() {
911
React = require.requireActual('react/dist/react-with-addons')
12+
ReactNative = require('react-native')
13+
ShallowTestUtils = require('react-shallow-testutils')
1014

1115
RefreshingIndicator = require('../RefreshingIndicator')
1216

@@ -16,15 +20,18 @@ describe('RefreshingIndicator', function() {
1620
it('renders an activity indicator', function() {
1721
let renderer = this.shallowRender(
1822
<RefreshingIndicator
19-
description={description}
23+
refreshingPrompt={description}
24+
isRefreshing={true}
2025
/>
2126
)
2227

2328
let rootEl = renderer.getRenderOutput()
24-
expect(rootEl).toBeReactElement()
29+
expect(rootEl).toBeReactElementOfType(ReactNative.View)
2530

26-
expect(
27-
React.Children.only(rootEl.props.children).props.children[0]
28-
).toBeReactElement()
31+
let textEl = ShallowTestUtils.findWithType(rootEl, ReactNative.Text)
32+
expect(textEl.props.children).toBe(description)
33+
34+
let indicatorEl = ShallowTestUtils.findWithType(rootEl, ReactNative.ActivityIndicatorIOS)
35+
expect(indicatorEl).not.toBeUndefined()
2936
})
3037
})

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
"<rootDir>/node_modules/react",
3535
"<rootDir>/node_modules/babel-core",
3636
"<rootDir>/node_modules/source-map-support",
37+
"<rootDir>/node_modules/inspect-react-element",
38+
"<rootDir>/node_modules/react-shallow-testutils",
39+
"<rootDir>/node_modules/react-addons-test-utils",
3740
"<rootDir>/node_modules/absolute-path",
3841
"<rootDir>/node_modules/xtend",
3942
"<rootDir>/node_modules/jasmine-object-matchers-jest",
@@ -54,15 +57,18 @@
5457
"babel-core": "^5.8.34",
5558
"eslint": "^0.19.0",
5659
"eslint-plugin-react": "^2.1.1",
60+
"inspect-react-element": "^1.1.1",
5761
"jasmine-object-matchers-jest": "^0.1.0",
5862
"jest-cli": "^0.8.2",
5963
"jscs": "^2.7.0",
60-
"react": "^0.13.1",
64+
"react": "^0.14.7",
65+
"react-addons-test-utils": "^0.14.7",
6166
"source-map-support": "^0.2.10",
6267
"watchy": "^0.6.4",
6368
"xtend": "^4.0.0"
6469
},
6570
"dependencies": {
66-
"is-promise": "^2.0.0"
71+
"is-promise": "^2.0.0",
72+
"jest-cli": "^0.9.0-fb2"
6773
}
6874
}

test/support/setupTestFramework.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
let fs = require('fs')
22
let sourceMapSupport = require('source-map-support')
33
let absolutePath = require('absolute-path')
4+
let inspectReactElement = require('inspect-react-element')
45
let sourceMapPath = require('./sourceMapPath')
56

67
sourceMapSupport.install({
@@ -18,7 +19,9 @@ sourceMapSupport.install({
1819
})
1920

2021
jasmine.getEnv().beforeEach(function() {
22+
let React = require.requireActual('react/dist/react-with-addons')
2123
this.shallowRender = require('./shallowRender')
24+
window.printElement = (el) => console.log('\n' + inspectReactElement(el))
2225

2326
jest.setMock('react-native', require.requireActual('../../lib/__mocks__/react-native'))
2427

@@ -32,7 +35,13 @@ jasmine.getEnv().beforeEach(function() {
3235
return typeof this.actual == 'function'
3336
},
3437
toBeReactElement() {
35-
return this.actual && typeof this.actual == 'object' && this.actual._isReactElement
38+
return React.isValidElement(this.actual)
39+
},
40+
toBeReactElementOfType(type) {
41+
return (
42+
React.isValidElement(this.actual) &&
43+
this.actual.type === type
44+
)
3645
},
3746
})
3847
})

test/support/shallowRender.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
var React = require('react/addons')
1+
var TestUtils = require('react-addons-test-utils')
22

33
function shallowRender(element) {
4-
var {TestUtils} = React.addons
54
var shallowRenderer = TestUtils.createRenderer()
65

76
// add a method to expose instantiated component

0 commit comments

Comments
 (0)