Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"curly": 0,
"camelcase": 0,
"react/jsx-boolean-value": 1,
"react/jsx-quotes": 1,
"jsx-quotes": 1,
"react/jsx-no-undef": 1,
"react/jsx-uses-react": 1,
"react/jsx-uses-vars": 1,
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
node_modules
lib
legit-tests.js
dom.js
middleware.js
middleware
no-dom.js
tests.js
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "legit-tests",
"version": "0.4.2",
"version": "0.4.3",
"description": "a chainable testing library for React",
"main": "lib/legit-tests.js",
"main": "legit-tests.js",
"scripts": {
"compile": "babel src --stage 0 --out-dir lib;",
"prepublish": "babel src --stage 0 --out-dir lib;",
"compile": "babel src --stage 0 --out-dir .;",
"prepublish": "babel src --stage 0 --out-dir .;",
"test": "mocha --opts ./mocha.opts; eslint ./src/ --ext .jsx,.js --global require,exports:true"
},
"repository": {
Expand Down
90 changes: 1 addition & 89 deletions src/legit-tests.js
Original file line number Diff line number Diff line change
@@ -1,94 +1,6 @@
/* globals global */
import './dom'
import React from 'react/addons';
let { TestUtils } = React.addons
global.React = React //expose React to tests so they can use jsx syntax when passing in components to the class
require('react/lib/ExecutionEnvironment').canUseDOM = true

import {Find, SetState, Simulate} from './middleware'

class Test {

constructor(component, config){
this.component = component

if(config && config.shallow === true){
let shallowRenderer = TestUtils.createRenderer();
shallowRenderer.render(component);
this.instance = shallowRenderer.getRenderOutput();
}
else{
this.instance = TestUtils.renderIntoDocument(component)
}

this.helpers = {}
return this
}

use(callback, data){
callback.call(this, data)
return this
}

element(select, callback) {
if(!this.helpers) return

let element
if(typeof select === 'string') {
element = this.helpers.elements[select]
callback.call(this, element)
return this
}

element = this.getFirst(this.helpers.elements)
select.call(this, element)
return this
}

test(callback) {
var params = this.params()
callback.call(params, params)
return this
}

params(){
var length = Object.keys(this.helpers).length
if(this.helpers.elements && length === 1) {
return Object.assign({}, this, this.helpers.elements)
}
return this
}

//private

getFirst(object){
for (let element in object) return object[element]
}

//Built in middleware

find(data){
Find.call(this, data)
return this
}

setState(data){
SetState.call(this, data)
return this
}

simulate(data){
Simulate.call(this, data)
return this
}

renderToString(callback){
var component = React.renderToStaticMarkup(this.component)
callback.call(null, component)
return this
}

}
import Test from './tests'

export default function TestWrapper(component, config){
return new Test(component, config)
Expand Down
5 changes: 5 additions & 0 deletions src/no-dom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test from './tests'

export default function TestWrapper(component, config){
return new Test(component, config)
}
89 changes: 89 additions & 0 deletions src/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React from 'react/addons';
let { TestUtils } = React.addons
global.React = React //expose React to tests so they can use jsx syntax when passing in components to the class
require('react/lib/ExecutionEnvironment').canUseDOM = true

import {Find, SetState, Simulate} from './middleware'

export default class Test {

constructor(component, config){
this.component = component

if(config && config.shallow === true){
let shallowRenderer = TestUtils.createRenderer();
shallowRenderer.render(component);
this.instance = shallowRenderer.getRenderOutput();
}
else{
this.instance = TestUtils.renderIntoDocument(component)
}

this.helpers = {}
return this
}

use(callback, data){
callback.call(this, data)
return this
}

element(select, callback) {
if(!this.helpers) return

let element
if(typeof select === 'string') {
element = this.helpers.elements[select]
callback.call(this, element)
return this
}

element = this.getFirst(this.helpers.elements)
select.call(this, element)
return this
}

test(callback) {
var params = this.params()
callback.call(params, params)
return this
}

params(){
var length = Object.keys(this.helpers).length
if(this.helpers.elements && length === 1) {
return Object.assign({}, this, this.helpers.elements)
}
return this
}

//private

getFirst(object){
for (let element in object) return object[element]
}

//Built in middleware

find(data){
Find.call(this, data)
return this
}

setState(data){
SetState.call(this, data)
return this
}

simulate(data){
Simulate.call(this, data)
return this
}

renderToString(callback){
var component = React.renderToStaticMarkup(this.component)
callback.call(null, component)
return this
}

}
15 changes: 15 additions & 0 deletions tests/no-dom.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Test from '../src/no-dom'
import {Find} from '../src/middleware'
import { expect } from 'chai';

import TestComponent from './component'

describe('no dom', () => {

it('should render the component', () => {
Test(<TestComponent test="wow"/>, {shallow: true})
.test(function() {
expect(this.instance).to.be.ok
})
});
});