diff --git a/.babelrc b/.babelrc index b0b9a96..8851ffa 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,9 @@ { - "stage": 0 + "presets": [ + "react", + "es2015" + ], + "plugins": [ + "transform-object-rest-spread" + ] } diff --git a/.gitignore b/.gitignore index 4955639..5a188d6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,4 @@ node_modules -lib -alt -/legit-tests.js -/dom.js -/middleware.js -/middleware -/no-dom.js -/tests.js +legit-tests.js +find-all.js npm-debug.log diff --git a/README.md b/README.md index af8a89f..8ba5f7e 100644 --- a/README.md +++ b/README.md @@ -1,163 +1,38 @@ ##Legit Tests -This is a super friendly testing library for React, inspired by express middleware, it's easily extendable. Why did I make this when you can use [React's Test Utils](https://facebook.github.io/react/docs/test-utils.html)? Because who likes typing out `scryRenderedDOMComponentsWithTag` and the other method names on there. Not only that, but setting up the render process is also a hassle. +Legit Tests version 2.0 is completely rebuilt and much simpler. It has been influenced by [enzyme](https://github.com/airbnb/enzyme) and some code from [react-shallow-testutils](https://github.com/sheepsteak/react-shallow-testutils). It is meant to be a complete testing solution for shallow rendering. The syntax is as short as possible for testing your components! -###Install +``` +npm install legit-tests@2.0.0-alpha-3 +``` -`npm install legit-tests --save` +###Example -##Example +Find -~~~js -import Test from 'legit-tests' -//or -import Test from 'legit-tests/no-dom' //don't include jsdom - -import { expect } from 'chai' -import sinon from 'sinon' -import TestComponent from './TestComponent' - -let spy = sinon.spy() - - -//Calling a prop -Test() -.find('button') -.simulate({method: 'click', element: 'button'}) -.test(() => { - expect(spy.called).to.be.true -}) - -//finding an element -Test() -.find('.box') -.elements('.box', (box) => { - expect(box.props.children).to.be.equal('found me!') +```js +it('should find id', () => { + const legit = test() + expect(legit.find('#sick').id).to.equal('sick') }) -~~~ - -##Middleware - -[Current list of Middleware](https://github.com/Legitcode/tests/wiki/Bundled-Middleware) - -You can write middleware to do anything you repeatedly use. You can pass `.use` a function, along with an object that it will take in. Each function will be injected with the current instance which includes: -- `component` - the actual component itself -- `instance` - the rendered component instance -- `helpers` - an array you can add on to with data for the end function - -**Example**: -- See `mixin` below, this syntax may soon be deprecated +``` -This is the setState function used above. -~~~js +Any method after .find is expected to be a prop on a component. -Test() -.use(SetState, {}) +That is it. You can find multiple nodes and access them like so: -... +```js +legit.find('.awesome').first().children +legit.find('.awesome').last().children +legit.find('.awesome').get(3).children +``` -export default function setState(state){ - this.instance.setState(state) -} -~~~ -##test - -The `.test` function will be given the component instance and the helpers array. You can use a regular function to reference `this` or an arrow function: - -~~~js -.test(({helpers, instance}) => { ... }) -.test(function() { - //this.instance, this.helpers -}) -~~~ - -##element - -Use `.element` if you're just testing an element you found with the `.find` method. The syntax is a little smaller: - -~~~js -Test() -.find('.box') -.element(box => { - expect(box.props.children).to.be.equal('found me!') -}) -//or specify the element - -.find('.box') -.find('div') -.element('.box', box => { - expect(box.props.children).to.be.equal('found me!') -}) +##Supported methods -~~~ +- Find -##mixin - -Use `.mixin` if you want to add new middleware as methods to `Test`. This gives a more natural way of using middleware: - -~~~js -// In this example, CustomFind middleware was added to Test by mixin -// and used if as it was a method on Test itself. - -Test() -.mixin({ - customFind: CustomFind -}) -.customFind('cells', 'table td') -.element('cells', cells => { - expect(cells.length).to.be.equal(10) -}) - -~~~ - -##DOM rendering -__Shallow__ -- uses React shallow rendering (no DOM) -~~~js -Test(, {shallow: true}) -.find('button') -.simulate({method: 'click', element: 'button'}) -.test(() => { - expect(spy.called).to.be.true -}) -~~~ - -__Normal__ -- React render into document fragment -~~~js -Test() -.find('button') -.simulate({method: 'click', element: 'button'}) -.test(() => { - expect(spy.called).to.be.true -}) -~~~ - -__fullDOM__ -- ReactDOM render into document.body.div of jsdom -~~~js -Test(
, {fullDOM: true}) -.test(function() { - expect(global.window.document.querySelector('section')) - .to.be.okay -}) -.clean() // restores the document.body to empty -~~~ - -You can see more examples in the tests directory. - -##Testing Alt Stores - -You can now test [Alt](http://alt.js.org/) stores using the same API. - -~~~js -import TestStore from 'legit-tests/alt/store' - -TestStore(MyStore, MyActions) -.setInitialState({ todos: todos }) -.addTodo({ title: "Get Beer", complete: false }) -.test(({ state }) => { - expect(state.todos).to.eql(expected); -}) -~~~ +Coming soon -You can see the [full documentation on the Wiki](https://github.com/Legitcode/tests/wiki/Alt-Stores) +- Simulate \ No newline at end of file diff --git a/mocha.opts b/mocha.opts index 3dda84b..18a5da7 100644 --- a/mocha.opts +++ b/mocha.opts @@ -1,4 +1,4 @@ --full-trace ---compilers js:babel/register +--compilers js:babel-register --harmony-proxies ---recursive ./tests/**/*.jsx +--recursive ./tests diff --git a/package.json b/package.json index e55df02..8945d96 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,12 @@ { "name": "legit-tests", - "version": "1.1.1", + "version": "2.0.0alpha-3", "description": "a chainable testing library for React", "main": "legit-tests.js", "scripts": { "compile": "babel src --out-dir .", "prepublish": "babel src --out-dir .", - "lint": "eslint ./src/ ./tests/ --ext .jsx,.js --global require,exports:true", - "mocha": "mocha --opts ./mocha.opts", - "test": "npm run mocha; npm run lint" + "test": "mocha --opts ./mocha.opts" }, "repository": { "type": "git", @@ -28,28 +26,20 @@ }, "homepage": "https://github.com/legitcode/tests#readme", "devDependencies": { - "alt": "^0.17.4", - "babel-core": "^5.8.25", - "babel-eslint": "^4.1.3", - "babel-loader": "^5.3.2", - "babel-runtime": "^5.8.25", + "babel-cli": "^6.6.5", + "babel-plugin-transform-object-rest-spread": "^6.6.5", + "babel-preset-es2015": "^6.6.0", + "babel-preset-react": "^6.5.0", + "babel-register": "^6.7.2", "chai": "^3.3.0", - "eslint": "^1.6.0", - "eslint-plugin-react": "^3.5.1", "expect": "^1.12.0", - "mocha": "^2.3.3", - "mocha-babel": "^3.0.0", - "react-hot-loader": "^1.3.0", - "sinon": "^1.17.1", - "webpack": "^1.12.2" + "mocha": "^2.4.5", + "react": "^0.14.7", + "react-addons-test-utils": "^0.14.7", + "sinon": "^1.17.1" }, - "dependencies": { - "babel": "^5.8.29", - "harmony-reflect": "^1.4.2", - "jsdom": "^6.5.1", - "lodash": "^3.10.1", - "react": "^0.14.0", - "react-addons-test-utils": "^0.14.0", - "react-dom": "^0.14.0" + "peerDependencies": { + "react-addons-test-utils": ">0.14.0", + "react": ">0.14.0" } } diff --git a/src/alt/alt.js b/src/alt/alt.js deleted file mode 100644 index 714e2eb..0000000 --- a/src/alt/alt.js +++ /dev/null @@ -1,3 +0,0 @@ -import Alt from 'alt' - -export default new Alt() diff --git a/src/alt/store.js b/src/alt/store.js deleted file mode 100644 index 43121be..0000000 --- a/src/alt/store.js +++ /dev/null @@ -1,31 +0,0 @@ -import 'harmony-reflect' - -class TestStore { - constructor(store, actions) { - this.store = store - this.actions = actions - } - - test(callback) { - callback.call(this, this.store) - return this - } -} - -export default function TestStoreWrapper(store, actions) { - var proxy = new Proxy(new TestStore(store, actions), { - get: function(target, name) { - if (name in target) { - return target[name] - } - else if (name in target.actions) { - return (params) => { - target.actions[name](params) - return proxy - } - } - } - }) - - return proxy -} diff --git a/src/dom.js b/src/dom.js deleted file mode 100644 index 7cc1030..0000000 --- a/src/dom.js +++ /dev/null @@ -1,19 +0,0 @@ -/* globals global */ -function propagateToGlobal (window) { - for (let key in window) { - if (!window.hasOwnProperty(key)) continue - if (key in global) continue - - global[key] = window[key] - } -} - -var jsdom = require('jsdom') - -var doc = jsdom.jsdom('') -var win = doc.defaultView - -global.document = doc -global.window = win - -propagateToGlobal(win) diff --git a/src/find-all.js b/src/find-all.js new file mode 100644 index 0000000..6b33d88 --- /dev/null +++ b/src/find-all.js @@ -0,0 +1,23 @@ + +import React from 'react'; + +/** + * Traverses the tree and returns all components that satisfy the function `test`. + * + * @param {ReactComponent} tree the tree to traverse + * @param {Function} test the test for each component + * @return {Array} the components that satisfied `test` + */ +export default function findAll(tree, test) { + let found = test(tree) ? [tree] : []; + + if (React.isValidElement(tree)) { + if (React.Children.count(tree.props.children) > 0) { + React.Children.forEach(tree.props.children, (child) => { + found = found.concat(findAll(child, test)); + }); + } + } + + return found; +} \ No newline at end of file diff --git a/src/legit-tests.js b/src/legit-tests.js index 3da155e..3069578 100644 --- a/src/legit-tests.js +++ b/src/legit-tests.js @@ -1,2 +1,40 @@ -import './dom' -export default from './tests' +import TestUtils from 'react-addons-test-utils' +import React from 'react' +import findAll from './find-all' + +export default (component) => { + let items + + const shallowRenderer = TestUtils.createRenderer() + shallowRenderer.render(component) + const instance = shallowRenderer.getRenderOutput(); + + const find = (term, child) => { + const selector = term.charAt(0) + + switch (selector) { + case '.': + items = findAll(instance, child => child.props ? child.props.className == term.slice(1) : false) + return { ...items[0].props, ...utils} + case '#': + items = findAll(instance, child => child.props ? child.props.id == term.slice(1) : false) + return { ...items[0].props, ...utils} + default: + items = findAll(instance, child => child.type ? child.type == term : false) + return { ...items[0].props, ...utils} + } + } + + const first = () => items[0].props + const last = () => items[items.length - 1].props + const get = (index) => items[index].props + + const utils = { + find, + first, + last, + get, + } + + return utils +} diff --git a/src/middleware.js b/src/middleware.js deleted file mode 100644 index be0b2e5..0000000 --- a/src/middleware.js +++ /dev/null @@ -1,11 +0,0 @@ -import Find from './middleware/find' -import SetState from './middleware/setState' -import Simulate from './middleware/simulate' -import Clean from './middleware/clean' - -export default { - Find, - SetState, - Simulate, - Clean -} diff --git a/src/middleware/clean.js b/src/middleware/clean.js deleted file mode 100644 index 5864544..0000000 --- a/src/middleware/clean.js +++ /dev/null @@ -1,7 +0,0 @@ -export default function Clean(){ - this.instance = null - this.elements = null - if (global.window){ - global.window.document.body.innerHTML = '' - } -} \ No newline at end of file diff --git a/src/middleware/find.js b/src/middleware/find.js deleted file mode 100644 index e0bc4df..0000000 --- a/src/middleware/find.js +++ /dev/null @@ -1,73 +0,0 @@ -import TestUtils from 'react-addons-test-utils' -import _ from 'lodash' - -export default function find(selector){ - - var self = this - var foundElements = [] - var elements - var selector - - if (_.isFunction(selector)){ - elements = TestUtils.scryRenderedComponentsWithType(this.instance, selector) - selector = (selector.name || selector.displayName).toLowerCase() - } else { - - var tokens = selector.split(/(?=\.)|(?=#)|(?=\[)/) - tokens - .forEach(function(subselector){ - var els - switch (subselector[0]){ - // class - case '.': - els = TestUtils.scryRenderedDOMComponentsWithClass(self.instance, subselector.slice(1)) - foundElements.push( Array.isArray(els) ? els : [els] ) - break - - // id - case '#': - els = TestUtils.findAllInRenderedTree(self.instance, function(component){ - if (component.id === subselector.slice(1)){ - return true - } - }) - foundElements.push( Array.isArray(els) ? els : [els] ) - break - - // data attribute - case '[': - var attributeName = _.first( subselector.slice(1,-1).split('=') ) - var attributeValue = subselector.slice(1,-1).split('=').slice(1).join('=').replace(/^"(.*)"$/, '$1') - - els = TestUtils.findAllInRenderedTree(self.instance, function(component){ - if (component.getAttribute) { - var val = component.getAttribute(attributeName) - if (val === attributeValue || (val === 'true' && attributeValue === '')){ - return true - } - } - }) - - foundElements.push( Array.isArray(els) ? els : [els] ) - break - - // tag - default: - els = TestUtils.scryRenderedDOMComponentsWithTag(self.instance, subselector) - foundElements.push( Array.isArray(els) ? els : [els] ) - break - } - }) - - elements = _.intersection.apply(_, foundElements) - } - - if (elements){ - if (Array.isArray(elements) && elements.length === 1) { - this.elements[selector] = elements[0] - } else { - this.elements[selector] = elements - } - } - -} diff --git a/src/middleware/setState.js b/src/middleware/setState.js deleted file mode 100644 index de71851..0000000 --- a/src/middleware/setState.js +++ /dev/null @@ -1,3 +0,0 @@ -export default function setState(state){ - this.instance.setState(state) -} diff --git a/src/middleware/simulate.js b/src/middleware/simulate.js deleted file mode 100644 index c669dd8..0000000 --- a/src/middleware/simulate.js +++ /dev/null @@ -1,15 +0,0 @@ -import TestUtils from 'react-addons-test-utils' - -export default function simulate(data) { - let element - if (data.element !== undefined ) { - element = Array.isArray(this.elements[data.element]) ? - this.elements[data.element][0] : this.elements[data.element] - } else { - throw new Error(`No element "${data.element}" is in elements`) - } - TestUtils.Simulate[data.method].call(this, - element, - data.options || null - ) -} diff --git a/src/no-dom.js b/src/no-dom.js deleted file mode 100644 index bf18cdb..0000000 --- a/src/no-dom.js +++ /dev/null @@ -1 +0,0 @@ -export default from './tests' diff --git a/src/tests.js b/src/tests.js deleted file mode 100644 index 9843689..0000000 --- a/src/tests.js +++ /dev/null @@ -1,82 +0,0 @@ -import TestUtils from 'react-addons-test-utils' -import ReactDOMServer from 'react-dom/server' -import ReactDOM from 'react-dom' -import React from 'react' -global.React = React - -import { Find, SetState, Simulate, Clean } from './middleware' - -function Test(component, config) { - - let instance - if (config && config.shallow === true) { - const shallowRenderer = TestUtils.createRenderer() - shallowRenderer.render(component) - instance = shallowRenderer.getRenderOutput() - } else if (config && config.fullDOM && global.window) { - var div = global.window.document.createElement('div') - global.window.document.body.appendChild(div) - instance = ReactDOM.render(component, div) - } else { - instance = TestUtils.renderIntoDocument(component) - } - - const testComponent = { - instance, - component, - elements: {}, - element(select, callback) { - let element - if (typeof select === 'string') { - element = this.elements[select] - callback.call(this, element) - return this - } - - if (Array.isArray(select)) { - const args = select.map(elem => this.elements[elem]) - callback.call(this, ...args) - return this - } - - if (Object.keys(this.elements).length === 1) { - select.call(this, this.elements[Object.keys(this.elements)[0]]) - } else { - throw new Error("There are multiple elements select one") - } - return this - }, - use(callback, data) { - callback.call(this, data) - return this - }, - mixin(spec) { - Object.keys(spec).forEach(key => { - this[key] = (...args) => { - spec[key].call(this, ...args) - return this - } - }) - return this - }, - test(callback) { - const param = {...this, ...this.elements} - callback.call(param, param) - return this - }, - renderToString(callback) { - const componentString = ReactDOMServer.renderToStaticMarkup(component) - callback.call(null, componentString) - return this - } - } - - return testComponent.mixin({ - find: Find, - setState: SetState, - simulate: Simulate, - clean: Clean - }) -} - -export default Test diff --git a/tests/components/component.jsx b/tests/components/component.jsx deleted file mode 100644 index 8eefa00..0000000 --- a/tests/components/component.jsx +++ /dev/null @@ -1,33 +0,0 @@ -import React, { Component } from 'react' -import TinyComponent from './tiny-component' -import OtherComponent from './other-component' - -export default class TestComponent extends Component { - constructor(props, context){ - super(props, context) - this.state = {} - } - - render(){ - return ( -
-
{this.state.test}
-

found me!

- - - - - - -
- ) - } -} diff --git a/tests/components/index.js b/tests/components/index.js deleted file mode 100644 index 39cd25d..0000000 --- a/tests/components/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export TestComponent from './component' -export TinyComponent from './tiny-component' diff --git a/tests/components/other-component.jsx b/tests/components/other-component.jsx deleted file mode 100644 index 350d915..0000000 --- a/tests/components/other-component.jsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from 'react' - -export default React.createClass({ - render: function() { - return - } -}) diff --git a/tests/components/test.jsx b/tests/components/test.jsx new file mode 100644 index 0000000..1f67a05 --- /dev/null +++ b/tests/components/test.jsx @@ -0,0 +1,29 @@ +import React from 'react' + +export default class Test extends React.Component{ + + constructor() { + super() + this.state = { + test: 'this is a test' + } + } + + render() { + return ( +
+ Hey there +

+

+
+ {this.state.test} +
+
+ another one +
+
+

+
+ ) + } +} \ No newline at end of file diff --git a/tests/components/tiny-component.jsx b/tests/components/tiny-component.jsx deleted file mode 100644 index fce3c7c..0000000 --- a/tests/components/tiny-component.jsx +++ /dev/null @@ -1,7 +0,0 @@ -import React, { Component } from 'react' - -export default class TinyComponent extends Component { - render() { - return
- } -} diff --git a/tests/element.jsx b/tests/element.jsx deleted file mode 100644 index 1ddc8d8..0000000 --- a/tests/element.jsx +++ /dev/null @@ -1,37 +0,0 @@ -import Test from '../src/legit-tests' -import { expect } from 'chai' - -import { TestComponent } from './components' - -describe('.element', () => { - - it('should find box', () => { - Test() - .find('.box') - .element(box => { - expect(box.props.children).to.be.equal('found me!') - }) - }) - - it('should find box, not div', () => { - Test() - .find('.box') - .find('div') - .element('.box', box => { - expect(box.props.children).to.be.equal('found me!') - }) - .element('div', div => { - expect(div.length).to.be.equal(2) - }) - }) - - it('should select multiple elements', () => { - Test() - .find('.box') - .find('div') - .element(['.box', 'div'], (box, div) => { - expect(div.length).to.be.equal(2) - expect(box.props.children).to.be.equal('found me!') - }) - }) -}) diff --git a/tests/find.js b/tests/find.js new file mode 100644 index 0000000..a93ad1c --- /dev/null +++ b/tests/find.js @@ -0,0 +1,30 @@ +import React from 'react' +import test from '../src/legit-tests' +import { expect } from 'chai' + +import Test from './components/test' + +describe('Find', () => { + it('should find id', () => { + const legit = test() + expect(legit.find('#sick').first().id).to.equal('sick') + expect(legit.find('#sick').id).to.equal('sick') + }) + + it('should find class', () => { + const legit = test() + expect(legit.find('.wow').children).to.equal('this is a test') + }) + + it('should find first and last', () => { + const legit = test() + + expect(legit.find('.awesome').first().children.props.id).to.equal('sick') + expect(legit.find('.awesome').last().children).to.equal('another one') + }) + it('should find by tag name', () => { + const legit = test() + + expect(legit.find('p').children.props.id).to.equal('sick') + }) +}) \ No newline at end of file diff --git a/tests/find.jsx b/tests/find.jsx deleted file mode 100644 index b38ff8b..0000000 --- a/tests/find.jsx +++ /dev/null @@ -1,67 +0,0 @@ -import Test from '../src/legit-tests' -import { Find } from '../src/middleware' -import { expect } from 'chai' - -import { TestComponent, TinyComponent } from './components' -import OtherComponent from './components/other-component' - -describe('Find middleware', () => { - it('should find div', () => { - Test() - .find('div') - .test(function() { - expect(this.elements.div[0].props.children).to.be.equal(undefined) - }) - }) - - it('should find p tag with class', () => { - Test() - .use(Find, 'p.box') - .test(function() { - expect(this.elements['p.box'].props.children).to.be.equal('found me!') - }) - - Test() - .use(Find, 'p.box') - .element('p.box',(box) => { - expect(box.innerHTML).to.be.equal('found me!') - }) - - }) - - it('should find p tag with data attribute', () => { - Test() - .use(Find, '[data-p-tag]') - .test(function() { - expect(this.elements['[data-p-tag]'].props.children).to.be.equal('found me!') - }) - - }) - - it('should find an input with a name attribute that equals \'bob\'', ()=>{ - Test() - .find('input[name="bob"]') - .find('input[name]') - .test(function(){ - expect(this.elements['input[name="bob"]'].className).equal('bob') - expect(this.elements['input[name]'].className).equal('notbob') - }) - }) - - it('should find a rendered component', () => { - Test() - .find(TinyComponent) - .test(({tinycomponent}) => { - expect(tinycomponent.props.test).to.be.equal('true') - }) - }) - - it('should find a rendered component created with `createClass`', () => { - Test() - .find(OtherComponent) - .test(function() { - let otherComponent = this.elements['other-component'] - expect(otherComponent.props.test).to.be.equal('true') - }) - }) -}) diff --git a/tests/full-dom.jsx b/tests/full-dom.jsx deleted file mode 100644 index fe0e57c..0000000 --- a/tests/full-dom.jsx +++ /dev/null @@ -1,18 +0,0 @@ -import Test from '../src/legit-tests' -import { expect } from 'chai' - -describe('Render into document.body', () => { - - it('should render and clean up component', () => { - Test(
, {fullDOM: true}) - .test(function() { - expect(global.window.document.querySelector('section')) - .to.not.equal(null) - }) - .clean() - - // clean should clean up the document.body - expect(global.window.document.body.innerHTML).to.equal('') - }) - -}) \ No newline at end of file diff --git a/tests/mixin.jsx b/tests/mixin.jsx deleted file mode 100644 index 1f13afa..0000000 --- a/tests/mixin.jsx +++ /dev/null @@ -1,20 +0,0 @@ -import Test from '../src/legit-tests' -import { Find } from '../src/middleware' -import { expect } from 'chai' - -import { TestComponent } from './components' - -describe('Mixin method', () => { - - it('should add Find as method to Test', () => { - Test() - .mixin({ - customFind: Find - }) - .customFind('div') - .element('div', div => { - expect(div.length).to.equal(2) - }) - }) - -}) diff --git a/tests/no-dom.jsx b/tests/no-dom.jsx deleted file mode 100644 index f8fdd72..0000000 --- a/tests/no-dom.jsx +++ /dev/null @@ -1,14 +0,0 @@ -import Test from '../src/no-dom' -import { expect } from 'chai' - -import { TestComponent } from './components' - -describe('no dom', () => { - - it('should render the component', () => { - Test(, {shallow: true}) - .test(function() { - expect(this.instance).to.be.ok - }) - }) -}) diff --git a/tests/renderToString.jsx b/tests/renderToString.jsx deleted file mode 100644 index 295cf4b..0000000 --- a/tests/renderToString.jsx +++ /dev/null @@ -1,17 +0,0 @@ -import Test from '../src/legit-tests' -import { expect } from 'chai' - -import { TestComponent } from './components' - -describe('Render To String', () => { - - it('should return the html of the component', () => { - Test() - .renderToString(string => { - expect(string).to.match(/Click Me/) - }) - .test(({instance}) => { - expect(instance).to.be.ok - }) - }) -}) diff --git a/tests/setState.jsx b/tests/setState.jsx deleted file mode 100644 index 3dc4488..0000000 --- a/tests/setState.jsx +++ /dev/null @@ -1,22 +0,0 @@ -import Test from '../src/legit-tests' -import { expect } from 'chai' -import { SetState, Find } from '../src/middleware' - -import { TestComponent } from './components' - -describe('setState middleware', () => { - - it('should change state', () => { - Test() - .use(SetState, {test: 'test'}) - .use(Find, 'div') - .test(({elements}) => { - expect(elements.div[0].props.children).to.be.equal('test') - }) - .setState({test: 'changed!'}) - .test(function() { - expect(this.instance.state.test).to.be.equal('changed!') - }) - }) - -}) diff --git a/tests/shallowRender.jsx b/tests/shallowRender.jsx deleted file mode 100644 index 9219ea5..0000000 --- a/tests/shallowRender.jsx +++ /dev/null @@ -1,15 +0,0 @@ -import Test from '../src/legit-tests' -import { expect } from 'chai' - -import { TestComponent } from './components' - -describe('Shallow Render', () => { - - it('should render the component', () => { - Test(, {shallow: true}) - .test(function() { - expect(this.instance).to.be.ok - }) - }) - -}) diff --git a/tests/simulate.jsx b/tests/simulate.jsx deleted file mode 100644 index d00cd65..0000000 --- a/tests/simulate.jsx +++ /dev/null @@ -1,30 +0,0 @@ -import Test from '../src/legit-tests' -import { expect } from 'chai' -import sinon from 'sinon' - -import { TestComponent } from './components' - -describe('simulate middleware', () => { - - it('should click a single element', () => { - let spy = sinon.spy() - - Test() - .find('div') - .simulate({method: 'click', element: 'div'}) - expect(spy.called).to.be.true - - }) - - it('should click the first element in an array', () => { - let spy = sinon.spy() - - Test() - .find('button') - .simulate({method: 'click', element: 'button'}) - - expect(spy.called).to.be.true - - }) - -})