Skip to content

Commit e5c266f

Browse files
committed
Finish porting examples
1 parent 110bf30 commit e5c266f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+80
-93
lines changed

examples/async/favicon.ico

-24.3 KB
Binary file not shown.

examples/async/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.1",
44
"private": true,
55
"devDependencies": {
6-
"react-scripts": "0.4.0",
6+
"react-scripts": "^0.4.0",
77
"redux-logger": "^2.6.1"
88
},
99
"dependencies": {
@@ -16,8 +16,7 @@
1616
"scripts": {
1717
"start": "react-scripts start",
1818
"build": "react-scripts build",
19-
"eject": "react-scripts eject",
20-
"test": "react-scripts test"
19+
"eject": "react-scripts eject"
2120
},
2221
"eslintConfig": {
2322
"extends": "./node_modules/react-scripts/config/eslint.js"

examples/buildAll.js

+21-14
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,27 @@ var exampleDirs = fs.readdirSync(__dirname).filter((file) => {
1010
return fs.statSync(path.join(__dirname, file)).isDirectory()
1111
})
1212

13-
for (const dir of exampleDirs) {
14-
// declare opts in this scope to avoid https://github.com/joyent/node/issues/9158
15-
const opts = {
16-
cwd: path.join(__dirname, dir),
17-
stdio: 'inherit'
18-
}
13+
// Ordering is important here. `npm install` must come first.
14+
var cmdArgs = [
15+
{ cmd: 'npm', args: [ 'install' ] },
16+
{ cmd: 'webpack', args: [ 'index.js' ] }
17+
]
1918

20-
let result = {}
21-
if (process.platform === 'win32') {
22-
result = spawnSync('npm.cmd', [ 'install' ], opts)
23-
} else {
24-
result = spawnSync('npm', [ 'install' ], opts)
25-
}
26-
if (result.status !== 0) {
27-
throw new Error('Building examples exited with non-zero')
19+
for (const dir of exampleDirs) {
20+
for (const cmdArg of cmdArgs) {
21+
// declare opts in this scope to avoid https://github.com/joyent/node/issues/9158
22+
const opts = {
23+
cwd: path.join(__dirname, dir),
24+
stdio: 'inherit'
25+
}
26+
let result = {}
27+
if (process.platform === 'win32') {
28+
result = spawnSync(cmdArg.cmd + '.cmd', cmdArg.args, opts)
29+
} else {
30+
result = spawnSync(cmdArg.cmd, cmdArg.args, opts)
31+
}
32+
if (result.status !== 0) {
33+
throw new Error('Building examples exited with non-zero')
34+
}
2835
}
2936
}

examples/counter/favicon.ico

-24.3 KB
Binary file not shown.

examples/counter/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"devDependencies": {
66
"enzyme": "^2.4.1",
77
"react-addons-test-utils": "^15.3.0",
8-
"react-scripts": "0.4.0"
8+
"react-scripts": "^0.4.0"
99
},
1010
"dependencies": {
1111
"react": "^15.3.0",

examples/counter/src/components/Counter.spec.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import expect from 'expect'
21
import React from 'react'
32
import { shallow } from 'enzyme'
43
import Counter from './Counter'
54

65
function setup(value = 0) {
76
const actions = {
8-
onIncrement: expect.createSpy(),
9-
onDecrement: expect.createSpy()
7+
onIncrement: jest.fn(),
8+
onDecrement: jest.fn()
109
}
1110
const component = shallow(
1211
<Counter value={value} {...actions} />
@@ -29,38 +28,38 @@ describe('Counter component', () => {
2928
it('first button should call onIncrement', () => {
3029
const { buttons, actions } = setup()
3130
buttons.at(0).simulate('click')
32-
expect(actions.onIncrement).toHaveBeenCalled()
31+
expect(actions.onIncrement).toBeCalled()
3332
})
3433

3534
it('second button should call onDecrement', () => {
3635
const { buttons, actions } = setup()
3736
buttons.at(1).simulate('click')
38-
expect(actions.onDecrement).toHaveBeenCalled()
37+
expect(actions.onDecrement).toBeCalled()
3938
})
4039

4140
it('third button should not call onIncrement if the counter is even', () => {
4241
const { buttons, actions } = setup(42)
4342
buttons.at(2).simulate('click')
44-
expect(actions.onIncrement).toNotHaveBeenCalled()
43+
expect(actions.onIncrement).not.toBeCalled()
4544
})
4645

4746
it('third button should call onIncrement if the counter is odd', () => {
4847
const { buttons, actions } = setup(43)
4948
buttons.at(2).simulate('click')
50-
expect(actions.onIncrement).toHaveBeenCalled()
49+
expect(actions.onIncrement).toBeCalled()
5150
})
5251

5352
it('third button should call onIncrement if the counter is odd and negative', () => {
5453
const { buttons, actions } = setup(-43)
5554
buttons.at(2).simulate('click')
56-
expect(actions.onIncrement).toHaveBeenCalled()
55+
expect(actions.onIncrement).toBeCalled()
5756
})
5857

5958
it('fourth button should call onIncrement in a second', (done) => {
6059
const { buttons, actions } = setup()
6160
buttons.at(3).simulate('click')
6261
setTimeout(() => {
63-
expect(actions.onIncrement).toHaveBeenCalled()
62+
expect(actions.onIncrement).toBeCalled()
6463
done()
6564
}, 1000)
6665
})

examples/counter/src/reducers/index.spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import expect from 'expect'
21
import counter from './index'
32

43
describe('reducers', () => {

examples/real-world/favicon.ico

-24.3 KB
Binary file not shown.

examples/real-world/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.1",
44
"private": true,
55
"devDependencies": {
6-
"react-scripts": "0.4.0",
6+
"react-scripts": "^0.4.0",
77
"redux-devtools": "^3.3.1",
88
"redux-devtools-dock-monitor": "^1.1.1",
99
"redux-devtools-log-monitor": "^1.0.11",
@@ -23,8 +23,7 @@
2323
"scripts": {
2424
"start": "react-scripts start",
2525
"build": "react-scripts build",
26-
"eject": "react-scripts eject",
27-
"test": "react-scripts test"
26+
"eject": "react-scripts eject"
2827
},
2928
"eslintConfig": {
3029
"extends": "./node_modules/react-scripts/config/eslint.js"

examples/shopping-cart/favicon.ico

-24.3 KB
Binary file not shown.

examples/shopping-cart/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"devDependencies": {
66
"enzyme": "^2.4.1",
77
"react-addons-test-utils": "^15.3.0",
8-
"react-scripts": "0.4.0"
8+
"react-scripts": "^0.4.0"
99
},
1010
"dependencies": {
1111
"react": "^15.3.0",

examples/shopping-cart/src/components/Cart.spec.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import expect from 'expect'
21
import React from 'react'
32
import { shallow } from 'enzyme'
43
import Cart from './Cart'
54
import Product from './Product'
65

76
function setup(total, products = []) {
87
const actions = {
9-
onCheckoutClicked: expect.createSpy()
8+
onCheckoutClicked: jest.fn()
109
}
1110

1211
const component = shallow(
@@ -68,7 +67,7 @@ describe('Cart component', () => {
6867
it('should call action on button click', () => {
6968
const { button, actions } = setup('9.99', product)
7069
button.simulate('click')
71-
expect(actions.onCheckoutClicked).toHaveBeenCalled()
70+
expect(actions.onCheckoutClicked).toBeCalled()
7271
})
7372
})
7473
})

examples/shopping-cart/src/components/Product.spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import expect from 'expect'
21
import React from 'react'
32
import { shallow } from 'enzyme'
43
import Product from './Product'

examples/shopping-cart/src/components/ProductItem.spec.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import expect from 'expect'
21
import React from 'react'
32
import { shallow } from 'enzyme'
43
import Product from './Product'
54
import ProductItem from './ProductItem'
65

76
function setup(product) {
87
const actions = {
9-
onAddToCartClicked: expect.createSpy()
8+
onAddToCartClicked: jest.fn()
109
}
1110

1211
const component = shallow(
@@ -50,7 +49,7 @@ describe('ProductItem component', () => {
5049
it('should call action on button click', () => {
5150
const { button, actions } = setup(productProps)
5251
button.simulate('click')
53-
expect(actions.onAddToCartClicked).toHaveBeenCalled()
52+
expect(actions.onAddToCartClicked).toBeCalled()
5453
})
5554

5655
describe('when product inventory is 0', () => {

examples/shopping-cart/src/components/ProductsList.spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import expect from 'expect'
21
import React from 'react'
32
import { shallow } from 'enzyme'
43
import ProductsList from './ProductsList'

examples/shopping-cart/src/reducers/cart.spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import expect from 'expect'
21
import cart from './cart'
32

43
describe('reducers', () => {

examples/shopping-cart/src/reducers/index.spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import expect from 'expect'
21
import { getTotal, getCartProducts } from './index'
32

43
describe('selectors', () => {

examples/shopping-cart/src/reducers/products.spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import expect from 'expect'
21
import products from './products'
32

43
describe('reducers', () => {

examples/todomvc/favicon.ico

-24.3 KB
Binary file not shown.

examples/todomvc/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"devDependencies": {
66
"enzyme": "^2.4.1",
77
"react-addons-test-utils": "^15.3.0",
8-
"react-scripts": "0.4.0"
8+
"react-scripts": "^0.4.0"
99
},
1010
"dependencies": {
1111
"classnames": "^2.2.5",

examples/todomvc/src/actions/index.spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import expect from 'expect'
21
import * as types from '../constants/ActionTypes'
32
import * as actions from './index'
43

examples/todomvc/src/components/Footer.spec.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import expect from 'expect'
21
import React from 'react'
32
import TestUtils from 'react-addons-test-utils'
43
import Footer from './Footer'
@@ -9,8 +8,8 @@ function setup(propOverrides) {
98
completedCount: 0,
109
activeCount: 0,
1110
filter: SHOW_ALL,
12-
onClearCompleted: expect.createSpy(),
13-
onShow: expect.createSpy()
11+
onClearCompleted: jest.fn(),
12+
onShow: jest.fn()
1413
}, propOverrides)
1514

1615
const renderer = TestUtils.createRenderer()
@@ -76,7 +75,7 @@ describe('components', () => {
7675
const [ , filters ] = output.props.children
7776
const filterLink = filters.props.children[1].props.children
7877
filterLink.props.onClick({})
79-
expect(props.onShow).toHaveBeenCalledWith(SHOW_ACTIVE)
78+
expect(props.onShow).toBeCalledWith(SHOW_ACTIVE)
8079
})
8180

8281
it('shouldnt show clear button when no completed todos', () => {
@@ -96,7 +95,7 @@ describe('components', () => {
9695
const { output, props } = setup({ completedCount: 1 })
9796
const [ , , clear ] = output.props.children
9897
clear.props.onClick({})
99-
expect(props.onClearCompleted).toHaveBeenCalled()
98+
expect(props.onClearCompleted).toBeCalled()
10099
})
101100
})
102101
})

examples/todomvc/src/components/Header.spec.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import expect from 'expect'
21
import React from 'react'
32
import TestUtils from 'react-addons-test-utils'
43
import Header from './Header'
54
import TodoTextInput from './TodoTextInput'
65

76
function setup() {
87
const props = {
9-
addTodo: expect.createSpy()
8+
addTodo: jest.fn()
109
}
1110

1211
const renderer = TestUtils.createRenderer()
@@ -42,9 +41,9 @@ describe('components', () => {
4241
const { output, props } = setup()
4342
const input = output.props.children[1]
4443
input.props.onSave('')
45-
expect(props.addTodo.calls.length).toBe(0)
44+
expect(props.addTodo).not.toBeCalled()
4645
input.props.onSave('Use Redux')
47-
expect(props.addTodo.calls.length).toBe(1)
46+
expect(props.addTodo).toBeCalled()
4847
})
4948
})
5049
})

examples/todomvc/src/components/MainSection.spec.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import expect from 'expect'
21
import React from 'react'
32
import TestUtils from 'react-addons-test-utils'
43
import MainSection from './MainSection'
@@ -20,11 +19,11 @@ function setup(propOverrides) {
2019
}
2120
],
2221
actions: {
23-
editTodo: expect.createSpy(),
24-
deleteTodo: expect.createSpy(),
25-
completeTodo: expect.createSpy(),
26-
completeAll: expect.createSpy(),
27-
clearCompleted: expect.createSpy()
22+
editTodo: jest.fn(),
23+
deleteTodo: jest.fn(),
24+
completeTodo: jest.fn(),
25+
completeAll: jest.fn(),
26+
clearCompleted: jest.fn()
2827
}
2928
}, propOverrides)
3029

@@ -73,7 +72,7 @@ describe('components', () => {
7372
const { output, props } = setup()
7473
const [ toggle ] = output.props.children
7574
toggle.props.onChange({})
76-
expect(props.actions.completeAll).toHaveBeenCalled()
75+
expect(props.actions.completeAll).toBeCalled()
7776
})
7877
})
7978

@@ -100,7 +99,7 @@ describe('components', () => {
10099
const { output, props } = setup()
101100
const [ , , footer ] = output.props.children
102101
footer.props.onClearCompleted()
103-
expect(props.actions.clearCompleted).toHaveBeenCalled()
102+
expect(props.actions.clearCompleted).toBeCalled()
104103
})
105104
})
106105

examples/todomvc/src/components/TodoItem.spec.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import expect from 'expect'
21
import React from 'react'
32
import TestUtils from 'react-addons-test-utils'
43
import TodoItem from './TodoItem'
@@ -11,9 +10,9 @@ function setup( editing = false ) {
1110
text: 'Use Redux',
1211
completed: false
1312
},
14-
editTodo: expect.createSpy(),
15-
deleteTodo: expect.createSpy(),
16-
completeTodo: expect.createSpy()
13+
editTodo: jest.fn(),
14+
deleteTodo: jest.fn(),
15+
completeTodo: jest.fn()
1716
}
1817

1918
const renderer = TestUtils.createRenderer()
@@ -66,14 +65,14 @@ describe('components', () => {
6665
const { output, props } = setup()
6766
const input = output.props.children.props.children[0]
6867
input.props.onChange({})
69-
expect(props.completeTodo).toHaveBeenCalledWith(0)
68+
expect(props.completeTodo).toBeCalledWith(0)
7069
})
7170

7271
it('button onClick should call deleteTodo', () => {
7372
const { output, props } = setup()
7473
const button = output.props.children.props.children[2]
7574
button.props.onClick({})
76-
expect(props.deleteTodo).toHaveBeenCalledWith(0)
75+
expect(props.deleteTodo).toBeCalledWith(0)
7776
})
7877

7978
it('label onDoubleClick should put component in edit state', () => {
@@ -100,13 +99,13 @@ describe('components', () => {
10099
it('TodoTextInput onSave should call editTodo', () => {
101100
const { output, props } = setup(true)
102101
output.props.children.props.onSave('Use Redux')
103-
expect(props.editTodo).toHaveBeenCalledWith(0, 'Use Redux')
102+
expect(props.editTodo).toBeCalledWith(0, 'Use Redux')
104103
})
105104

106105
it('TodoTextInput onSave should call deleteTodo if text is empty', () => {
107106
const { output, props } = setup(true)
108107
output.props.children.props.onSave('')
109-
expect(props.deleteTodo).toHaveBeenCalledWith(0)
108+
expect(props.deleteTodo).toBeCalledWith(0)
110109
})
111110

112111
it('TodoTextInput onSave should exit component from edit state', () => {

0 commit comments

Comments
 (0)