diff --git a/.eslintrc b/.eslintrc index b41af79..fa2e1f3 100644 --- a/.eslintrc +++ b/.eslintrc @@ -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, diff --git a/.gitignore b/.gitignore index 491fc35..4c48861 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,7 @@ node_modules -lib +legit-tests.js +dom.js +middleware.js +middleware +no-dom.js +tests.js diff --git a/package.json b/package.json index 0c8272e..b6ea835 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/legit-tests.js b/src/legit-tests.js index c43a3c1..8c6dac3 100644 --- a/src/legit-tests.js +++ b/src/legit-tests.js @@ -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) diff --git a/src/no-dom.js b/src/no-dom.js new file mode 100644 index 0000000..646b307 --- /dev/null +++ b/src/no-dom.js @@ -0,0 +1,5 @@ +import Test from './tests' + +export default function TestWrapper(component, config){ + return new Test(component, config) +} diff --git a/src/tests.js b/src/tests.js new file mode 100644 index 0000000..c22701e --- /dev/null +++ b/src/tests.js @@ -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 + } + +} diff --git a/tests/no-dom.jsx b/tests/no-dom.jsx new file mode 100644 index 0000000..05fd551 --- /dev/null +++ b/tests/no-dom.jsx @@ -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(, {shallow: true}) + .test(function() { + expect(this.instance).to.be.ok + }) + }); +});