Skip to content

Commit 10a7381

Browse files
committed
Merge pull request #17 from Legitcode/feature/element
added .element
2 parents 5638cba + 16b03c6 commit 10a7381

3 files changed

Lines changed: 57 additions & 12 deletions

File tree

package.json

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "legit-tests",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"description": "a chainable testing library for React",
55
"main": "lib/legit-tests.js",
66
"scripts": {
@@ -27,22 +27,20 @@
2727
"homepage": "https://github.com/legitcode/tests#readme",
2828
"devDependencies": {
2929
"babel": "^5.8.23",
30-
"babel-core": "^5.8.23",
31-
"babel-eslint": "^4.1.1",
30+
"babel-core": "^5.8.25",
31+
"babel-eslint": "^4.1.3",
3232
"babel-loader": "^5.3.2",
33-
"chai": "^3.2.0",
34-
"eslint": "^0.24.1",
35-
"eslint-plugin-react": "^2.7.0",
36-
"expect": "^1.8.0",
37-
"mocha": "^2.2.5",
33+
"chai": "^3.3.0",
34+
"eslint": "^1.5.1",
35+
"eslint-plugin-react": "^3.4.2",
36+
"expect": "^1.10.0",
37+
"mocha": "^2.3.3",
3838
"mocha-babel": "^3.0.0",
3939
"react-hot-loader": "^1.3.0",
40-
"sinon": "^1.16.1",
41-
"webpack": "^1.12.1",
42-
"webpack-dev-server": "^1.10.1"
40+
"sinon": "^1.17.0"
4341
},
4442
"dependencies": {
45-
"jsdom": "^6.5.0",
43+
"jsdom": "^6.5.1",
4644
"react": "^0.13.3"
4745
}
4846
}

src/legit-tests.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ class Test {
3030
return this
3131
}
3232

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+
3348
test(callback) {
3449
var params = this.params()
3550
callback.call(params, params)
@@ -44,6 +59,12 @@ class Test {
4459
return this
4560
}
4661

62+
//private
63+
64+
getFirst(object){
65+
for (let element in object) return object[element]
66+
}
67+
4768
//Built in middleware
4869

4970
find(data){

tests/element.jsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Test from '../src/legit-tests'
2+
import {Find} from '../src/middleware'
3+
import { expect } from 'chai';
4+
5+
import TestComponent from './component'
6+
import TinyComponent from './tiny-component'
7+
8+
describe('.element', () => {
9+
10+
it('should find box', () => {
11+
Test(<TestComponent/>)
12+
.find('.box')
13+
.element(box => {
14+
expect(box.props.children).to.be.equal('found me!')
15+
})
16+
});
17+
18+
it('should find box, not div', () => {
19+
Test(<TestComponent/>)
20+
.find('.box')
21+
.find('div')
22+
.element('box', box => {
23+
expect(box.props.children).to.be.equal('found me!')
24+
})
25+
});
26+
});

0 commit comments

Comments
 (0)