Skip to content

Commit 19c6843

Browse files
committed
Merge pull request #24 from vramana/newer-api
[WIP] Refine API
2 parents 88529c9 + 288413b commit 19c6843

24 files changed

Lines changed: 266 additions & 203 deletions

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"stage": 0
3+
}

.eslintrc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"parser": "babel-eslint",
33
"env": {
4-
"es6": true
4+
"es6": true,
5+
"mocha": true,
6+
"node": true
57
},
68
"ecmaFeatures": {
79
"blockBindings": true,
@@ -14,6 +16,9 @@
1416
"max-len": 0,
1517
"semi": 0,
1618
"quotes": 0,
19+
"semi": [2, "never"],
20+
"no-unused-vars": 2,
21+
"no-undef": 2,
1722
"no-console": 0,
1823
"no-trailing-spaces": 0,
1924
"curly": 0,
@@ -27,7 +32,7 @@
2732
"react/no-did-update-set-state": 1,
2833
"react/no-multi-comp": 1,
2934
"react/no-unknown-property": 1,
30-
"react/prop-types": 1,
35+
"react/prop-types": 0,
3136
"react/react-in-jsx-scope": 1,
3237
"react/self-closing-comp": 1,
3338
"react/sort-comp": 1,

.gitignore

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
node_modules
2-
legit-tests.js
3-
dom.js
4-
middleware.js
5-
middleware
6-
no-dom.js
7-
tests.js
2+
lib
3+
/legit-tests.js
4+
/dom.js
5+
/middleware.js
6+
/middleware
7+
/no-dom.js
8+
/tests.js
9+
npm-debug.log

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,25 @@ Test(<TestComponent/>)
9494

9595
~~~
9696

97+
##mixin
98+
99+
Use `.mixin` if you want to add new middleware as methods to `Test`. This gives a more natural way of using middleware:
100+
101+
~~~js
102+
// In this example, CustomFind middleware was added to Test by mixin
103+
// and used if as it was a method on Test itself.
104+
105+
Test(<TestComponent />)
106+
.mixin({
107+
customFind: CustomFind
108+
})
109+
.customFind('cells', 'table td')
110+
.element('cells', cells => {
111+
expect(cells.length).to.be.equal(10)
112+
})
113+
114+
~~~
115+
116+
117+
97118
You can see more examples in the tests directory.

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
"description": "a chainable testing library for React",
55
"main": "legit-tests.js",
66
"scripts": {
7-
"compile": "babel src --stage 0 --out-dir .;",
8-
"prepublish": "babel src --stage 0 --out-dir .;",
9-
"test": "mocha --opts ./mocha.opts; eslint ./src/ --ext .jsx,.js --global require,exports:true"
7+
"compile": "babel src --out-dir .",
8+
"prepublish": "babel src --out-dir .",
9+
"lint": "eslint ./src/ ./tests/ --ext .jsx,.js --global require,exports:true",
10+
"mocha": "mocha --opts ./mocha.opts",
11+
"test": "npm run mocha; npm run lint"
1012
},
1113
"repository": {
1214
"type": "git",
@@ -30,14 +32,16 @@
3032
"babel-core": "^5.8.25",
3133
"babel-eslint": "^4.1.3",
3234
"babel-loader": "^5.3.2",
35+
"babel-runtime": "^5.8.25",
3336
"chai": "^3.3.0",
3437
"eslint": "^1.5.1",
3538
"eslint-plugin-react": "^3.4.2",
3639
"expect": "^1.10.0",
3740
"mocha": "^2.3.3",
3841
"mocha-babel": "^3.0.0",
3942
"react-hot-loader": "^1.3.0",
40-
"sinon": "^1.17.0"
43+
"sinon": "^1.17.0",
44+
"webpack": "^1.12.2"
4145
},
4246
"dependencies": {
4347
"jsdom": "^6.5.1",

src/dom.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ function propagateToGlobal (window) {
88
}
99
}
1010

11-
var jsdom = require('jsdom');
11+
var jsdom = require('jsdom')
1212

13-
var doc = jsdom.jsdom('<!doctype html><html><body></body></html>');
14-
var win = doc.defaultView;
13+
var doc = jsdom.jsdom('<!doctype html><html><body></body></html>')
14+
var win = doc.defaultView
1515

16-
global.document = doc;
17-
global.window = win;
16+
global.document = doc
17+
global.window = win
1818

19-
propagateToGlobal(win);
19+
propagateToGlobal(win)

src/legit-tests.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
1-
/* globals global */
21
import './dom'
3-
import Test from './tests'
4-
5-
export default function TestWrapper(component, config){
6-
return new Test(component, config)
7-
}
2+
export default from './tests'

src/middleware/find.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ export default function find(selector){
1212
}
1313
else elements = TestUtils.scryRenderedDOMComponentsWithTag(this.instance, selector)
1414

15-
if(elements.length === 1) elements = elements[0]
16-
if(!this.helpers.elements) this.helpers.elements = []
17-
this.helpers.elements[name || selector] = elements
15+
if (Array.isArray(elements) && elements.length === 1) {
16+
this.elements[name || selector] = elements[0]
17+
} else {
18+
this.elements[name || selector] = elements
19+
}
1820
}

src/middleware/simulate.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import React from 'react'
22
let { TestUtils } = React.addons
33

4-
export default function simulate(data){
5-
let element = data.element ? this.helpers.elements[data.element] : this;
6-
element = Array.isArray(element) ? element[0] : element;
4+
export default function simulate(data) {
5+
let element
6+
if (data.element !== undefined ) {
7+
element = Array.isArray(this.elements[data.element]) ?
8+
this.elements[data.element][0] : this.elements[data.element]
9+
} else {
10+
throw new Error(`No element "${data.element}" is in elements`)
11+
}
712
TestUtils.Simulate[data.method].call(this,
813
element,
914
data.options || null
10-
);
15+
)
1116
}

src/no-dom.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
import Test from './tests'
2-
3-
export default function TestWrapper(component, config){
4-
return new Test(component, config)
5-
}
1+
export default from './tests'

0 commit comments

Comments
 (0)