Skip to content

Commit 6b670e7

Browse files
committed
added separate file for no including the dom
1 parent 838a447 commit 6b670e7

5 files changed

Lines changed: 98 additions & 92 deletions

File tree

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"curly": 0,
2020
"camelcase": 0,
2121
"react/jsx-boolean-value": 1,
22-
"react/jsx-quotes": 1,
22+
"jsx-quotes": 1,
2323
"react/jsx-no-undef": 1,
2424
"react/jsx-uses-react": 1,
2525
"react/jsx-uses-vars": 1,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"name": "legit-tests",
33
"version": "0.4.2",
44
"description": "a chainable testing library for React",
5-
"main": "lib/legit-tests.js",
5+
"main": "legit-tests.js",
66
"scripts": {
7-
"compile": "babel src --stage 0 --out-dir lib;",
7+
"compile": "babel src --stage 0 --out-dir .;",
88
"prepublish": "babel src --stage 0 --out-dir lib;",
99
"test": "mocha --opts ./mocha.opts; eslint ./src/ --ext .jsx,.js --global require,exports:true"
1010
},

src/legit-tests.js

Lines changed: 1 addition & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,6 @@
11
/* globals global */
22
import './dom'
3-
import React from 'react/addons';
4-
let { TestUtils } = React.addons
5-
global.React = React //expose React to tests so they can use jsx syntax when passing in components to the class
6-
require('react/lib/ExecutionEnvironment').canUseDOM = true
7-
8-
import {Find, SetState, Simulate} from './middleware'
9-
10-
class Test {
11-
12-
constructor(component, config){
13-
this.component = component
14-
15-
if(config && config.shallow === true){
16-
let shallowRenderer = TestUtils.createRenderer();
17-
shallowRenderer.render(component);
18-
this.instance = shallowRenderer.getRenderOutput();
19-
}
20-
else{
21-
this.instance = TestUtils.renderIntoDocument(component)
22-
}
23-
24-
this.helpers = {}
25-
return this
26-
}
27-
28-
use(callback, data){
29-
callback.call(this, data)
30-
return this
31-
}
32-
33-
element(select, callback) {
34-
if(!this.helpers) return
35-
36-
let element
37-
if(typeof select === 'string') {
38-
element = this.helpers.elements[select]
39-
callback.call(this, element)
40-
return this
41-
}
42-
43-
element = this.getFirst(this.helpers.elements)
44-
select.call(this, element)
45-
return this
46-
}
47-
48-
test(callback) {
49-
var params = this.params()
50-
callback.call(params, params)
51-
return this
52-
}
53-
54-
params(){
55-
var length = Object.keys(this.helpers).length
56-
if(this.helpers.elements && length === 1) {
57-
return Object.assign({}, this, this.helpers.elements)
58-
}
59-
return this
60-
}
61-
62-
//private
63-
64-
getFirst(object){
65-
for (let element in object) return object[element]
66-
}
67-
68-
//Built in middleware
69-
70-
find(data){
71-
Find.call(this, data)
72-
return this
73-
}
74-
75-
setState(data){
76-
SetState.call(this, data)
77-
return this
78-
}
79-
80-
simulate(data){
81-
Simulate.call(this, data)
82-
return this
83-
}
84-
85-
renderToString(callback){
86-
var component = React.renderToStaticMarkup(this.component)
87-
callback.call(null, component)
88-
return this
89-
}
90-
91-
}
3+
import Test from './tests'
924

935
export default function TestWrapper(component, config){
946
return new Test(component, config)

src/no-dom.js

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

src/tests.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import React from 'react/addons';
2+
let { TestUtils } = React.addons
3+
global.React = React //expose React to tests so they can use jsx syntax when passing in components to the class
4+
require('react/lib/ExecutionEnvironment').canUseDOM = true
5+
6+
import {Find, SetState, Simulate} from './middleware'
7+
8+
export default class Test {
9+
10+
constructor(component, config){
11+
this.component = component
12+
13+
if(config && config.shallow === true){
14+
let shallowRenderer = TestUtils.createRenderer();
15+
shallowRenderer.render(component);
16+
this.instance = shallowRenderer.getRenderOutput();
17+
}
18+
else{
19+
this.instance = TestUtils.renderIntoDocument(component)
20+
}
21+
22+
this.helpers = {}
23+
return this
24+
}
25+
26+
use(callback, data){
27+
callback.call(this, data)
28+
return this
29+
}
30+
31+
element(select, callback) {
32+
if(!this.helpers) return
33+
34+
let element
35+
if(typeof select === 'string') {
36+
element = this.helpers.elements[select]
37+
callback.call(this, element)
38+
return this
39+
}
40+
41+
element = this.getFirst(this.helpers.elements)
42+
select.call(this, element)
43+
return this
44+
}
45+
46+
test(callback) {
47+
var params = this.params()
48+
callback.call(params, params)
49+
return this
50+
}
51+
52+
params(){
53+
var length = Object.keys(this.helpers).length
54+
if(this.helpers.elements && length === 1) {
55+
return Object.assign({}, this, this.helpers.elements)
56+
}
57+
return this
58+
}
59+
60+
//private
61+
62+
getFirst(object){
63+
for (let element in object) return object[element]
64+
}
65+
66+
//Built in middleware
67+
68+
find(data){
69+
Find.call(this, data)
70+
return this
71+
}
72+
73+
setState(data){
74+
SetState.call(this, data)
75+
return this
76+
}
77+
78+
simulate(data){
79+
Simulate.call(this, data)
80+
return this
81+
}
82+
83+
renderToString(callback){
84+
var component = React.renderToStaticMarkup(this.component)
85+
callback.call(null, component)
86+
return this
87+
}
88+
89+
}

0 commit comments

Comments
 (0)