(component, config)
| 7 | import { Find, SetState, Simulate, Clean } from './middleware' |
| 8 | |
| 9 | function Test(component, config) { |
| 10 | |
| 11 | let instance |
| 12 | if (config && config.shallow === true) { |
| 13 | const shallowRenderer = TestUtils.createRenderer() |
| 14 | shallowRenderer.render(component) |
| 15 | instance = shallowRenderer.getRenderOutput() |
| 16 | } else if (config && config.fullDOM && global.window) { |
| 17 | var div = global.window.document.createElement('div') |
| 18 | global.window.document.body.appendChild(div) |
| 19 | instance = ReactDOM.render(component, div) |
| 20 | } else { |
| 21 | instance = TestUtils.renderIntoDocument(component) |
| 22 | } |
| 23 | |
| 24 | const testComponent = { |
| 25 | instance, |
| 26 | component, |
| 27 | elements: {}, |
| 28 | element(select, callback) { |
| 29 | let element |
| 30 | if (typeof select === 'string') { |
| 31 | element = this.elements[select] |
| 32 | callback.call(this, element) |
| 33 | return this |
| 34 | } |
| 35 | |
| 36 | if (Array.isArray(select)) { |
| 37 | const args = select.map(elem => this.elements[elem]) |
| 38 | callback.call(this, ...args) |
| 39 | return this |
| 40 | } |
| 41 | |
| 42 | if (Object.keys(this.elements).length === 1) { |
| 43 | select.call(this, this.elements[Object.keys(this.elements)[0]]) |
| 44 | } else { |
| 45 | throw new Error("There are multiple elements select one") |
| 46 | } |
| 47 | return this |
| 48 | }, |
| 49 | use(callback, data) { |
| 50 | callback.call(this, data) |
| 51 | return this |
| 52 | }, |
| 53 | mixin(spec) { |
| 54 | Object.keys(spec).forEach(key => { |
| 55 | this[key] = (...args) => { |
| 56 | spec[key].call(this, ...args) |
| 57 | return this |
| 58 | } |
| 59 | }) |
| 60 | return this |
| 61 | }, |
| 62 | test(callback) { |
| 63 | const param = {...this, ...this.elements} |
| 64 | callback.call(param, param) |
| 65 | return this |
| 66 | }, |
no test coverage detected