Skip to content

Commit 2b63a36

Browse files
committed
Tests added for basic connect functionality.
1 parent ffb420f commit 2b63a36

File tree

6 files changed

+127
-28
lines changed

6 files changed

+127
-28
lines changed

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"plugins": [
44
"es6-promise",
55
"add-module-exports",
6-
"lodash"
6+
"lodash",
7+
"transform-decorators-legacy"
78
]
89
}

package.json

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
{
22
"name": "react-redux-firebase",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "A Higher Order Component to use Firebase version 3 with Redux",
55
"main": "dist/index.js",
66
"module": "src/index.js",
77
"jsnext:main": "src/index.js",
8-
"files": [
9-
"dist",
10-
"src"
11-
],
128
"scripts": {
139
"build": "babel src --out-dir dist",
1410
"build-dev": "babel src --out-dir dist --watch --src-maps inline",
@@ -47,26 +43,6 @@
4743
"url": "https://github.com/tiberiuc"
4844
}
4945
],
50-
"license": "MIT",
51-
"repository": {
52-
"type": "git",
53-
"url": "git+https://github.com/prescottprue/react-redux-firebase.git"
54-
},
55-
"bugs": {
56-
"url": "https://github.com/prescottprue/react-redux-firebase/issues"
57-
},
58-
"homepage": "https://github.com/prescottprue/react-redux-firebase#readme",
59-
"keywords": [
60-
"firebase",
61-
"redux",
62-
"react",
63-
"react-redux",
64-
"redux-firebase",
65-
"react",
66-
"babel",
67-
"hoc",
68-
"react-redux-firebase"
69-
],
7046
"dependencies": {
7147
"firebase": "^3.5.0",
7248
"immutable": "^3.8.1",
@@ -85,6 +61,7 @@
8561
"babel-plugin-add-module-exports": "^0.2.1",
8662
"babel-plugin-es6-promise": "^1.0.0",
8763
"babel-plugin-lodash": "^3.2.9",
64+
"babel-plugin-transform-decorators-legacy": "^1.3.4",
8865
"babel-preset-es2015": "^6.16.0",
8966
"babel-preset-react": "^6.16.0",
9067
"babel-preset-stage-1": "^6.16.0",
@@ -98,10 +75,37 @@
9875
"eslint-plugin-react": "^6.4.1",
9976
"eslint-plugin-standard": "^2.0.1",
10077
"isparta": "^4.0.0",
78+
"jsdom": "^9.8.0",
10179
"mocha": "^3.1.2",
80+
"react-addons-test-utils": "^15.3.2",
81+
"react-dom": "^15.3.2",
10282
"rimraf": "^2.5.4"
10383
},
84+
"license": "MIT",
85+
"repository": {
86+
"type": "git",
87+
"url": "git+https://github.com/prescottprue/react-redux-firebase.git"
88+
},
89+
"bugs": {
90+
"url": "https://github.com/prescottprue/react-redux-firebase/issues"
91+
},
92+
"homepage": "https://github.com/prescottprue/react-redux-firebase#readme",
93+
"keywords": [
94+
"firebase",
95+
"redux",
96+
"react",
97+
"react-redux",
98+
"redux-firebase",
99+
"react",
100+
"babel",
101+
"hoc",
102+
"react-redux-firebase"
103+
],
104104
"npmName": "react-redux-firebase",
105+
"files": [
106+
"dist",
107+
"src"
108+
],
105109
"npmFileMap": [
106110
{
107111
"basePath": "/dist/",

test/setup.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ process.env.NODE_ENV = 'test'
44

55
var chai = global.chai = require('chai')
66
var expect = global.expect = chai.expect
7+
8+
import { jsdom } from 'jsdom'
9+
10+
global.document = jsdom('<!doctype html><html><body></body></html>')
11+
global.window = document.defaultView
12+
global.navigator = global.window.navigator

test/unit/connect.spec.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import React, { createClass, Children, PropTypes, Component } from 'react'
2+
import ReactDOM from 'react-dom'
3+
import connect from '../../src/connect'
4+
import reduxFirebase from '../../src/compose'
5+
import TestUtils from 'react-addons-test-utils'
6+
import { createStore, compose, combineReducers } from 'redux'
7+
8+
const apiKey = 'AIzaSyCTUERDM-Pchn_UDTsfhVPiwM4TtNIxots'
9+
const authDomain = 'redux-firebasev3.firebaseapp.com'
10+
const databaseURL = 'https://redux-firebasev3.firebaseio.com'
11+
const testFbConfig = {
12+
databaseURL,
13+
apiKey,
14+
authDomain
15+
}
16+
17+
describe('Connect', () => {
18+
class Passthrough extends Component {
19+
render () {
20+
return <div>{JSON.stringify(this.props)}</div>
21+
}
22+
}
23+
24+
class ProviderMock extends Component {
25+
getChildContext () {
26+
return { store: this.props.store }
27+
}
28+
29+
render () {
30+
return Children.only(this.props.children)
31+
}
32+
}
33+
34+
ProviderMock.childContextTypes = {
35+
store: PropTypes.object.isRequired
36+
}
37+
38+
function stringBuilder (prev = '', action) {
39+
return action.type === 'APPEND'
40+
? prev + action.body
41+
: prev
42+
}
43+
44+
it('throws for invalid databaseURL', () => {
45+
const createStoreWithMiddleware = compose(
46+
reduxFirebase({}, { userProfile: 'users' }),
47+
typeof window === 'object' && typeof window.devToolsExtension !== 'undefined' ? window.devToolsExtension() : f => f
48+
)(createStore)
49+
50+
expect(createStoreWithMiddleware).to.throw(Error)
51+
})
52+
53+
it('throws for invalid authDomain', () => {
54+
const createStoreWithMiddleware = compose(
55+
reduxFirebase({ databaseURL }, { userProfile: 'users' }),
56+
typeof window === 'object' && typeof window.devToolsExtension !== 'undefined' ? window.devToolsExtension() : f => f
57+
)(createStore)
58+
59+
expect(createStoreWithMiddleware).to.throw(Error)
60+
})
61+
62+
it('should receive the store in the context', () => {
63+
const createStoreWithMiddleware = compose(
64+
reduxFirebase(testFbConfig, { userProfile: 'users' }),
65+
typeof window === 'object' && typeof window.devToolsExtension !== 'undefined' ? window.devToolsExtension() : f => f
66+
)(createStore)
67+
const store = createStoreWithMiddleware(combineReducers({ test: (state = {}) => state }))
68+
69+
@connect()
70+
class Container extends Component {
71+
render() {
72+
return <Passthrough {...this.props} />
73+
}
74+
}
75+
76+
const tree = TestUtils.renderIntoDocument(
77+
<ProviderMock store={store}>
78+
<Container pass="through" />
79+
</ProviderMock>
80+
)
81+
82+
const container = TestUtils.findRenderedComponentWithType(tree, Container)
83+
expect(container.context.store).to.equal(store)
84+
})
85+
86+
87+
})

test/unit/helpers.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* global describe expect it */
22
import helpers from '../../src/helpers'
3-
const exampleData = { data: { some: 'data' }}
3+
const exampleData = { data: { some: 'data' } }
4+
45
describe('helpers', () => {
56
it('toJS', () => {
67
describe('exists', () => {

test/unit/library.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* global describe expect it */
22
import src from '../../src'
33

4-
describe('redux-firebasev3', () => {
4+
describe('module', () => {
55
describe('exports', () => {
66
it('firebase', () => {
77
expect(src).to.respondTo('firebase')

0 commit comments

Comments
 (0)