|
1 | 1 | /* globals global */ |
2 | 2 | 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' |
92 | 4 |
|
93 | 5 | export default function TestWrapper(component, config){ |
94 | 6 | return new Test(component, config) |
|
0 commit comments