Skip to content

Commit a5de7d6

Browse files
committed
Merge pull request #6 from jdfreder/test
Add tests
2 parents cffee08 + 216bff3 commit a5de7d6

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: node_js
2+
node_js:
3+
- "5"

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "ANSI to React Elements",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "mocha 'test/**/*.js'"
88
},
99
"keywords": [
1010
"ansi",
@@ -17,5 +17,13 @@
1717
},
1818
"peerDependencies": {
1919
"react": "^0.14.0 || ^15.0.0-0"
20+
},
21+
"devDependencies": {
22+
"chai": "^3.5.0",
23+
"enzyme": "^2.2.0",
24+
"mocha": "^2.4.5",
25+
"react": "^15.0.1",
26+
"react-addons-test-utils": "^15.0.1",
27+
"react-dom": "^15.0.1"
2028
}
2129
}

test/index-spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const Ansi = require('../index');
2+
const React = require('react');
3+
const expect = require('chai').expect;
4+
const enzyme = require('enzyme');
5+
6+
const GREEN_FG = '\u001b[32m';
7+
const YELLOW_BG = '\u001b[43m';
8+
const RESET = '\u001b[0;m';
9+
10+
describe('Ansi', () => {
11+
it('hello world', () => {
12+
const el = enzyme.shallow(React.createElement(Ansi, null, 'hello world'));
13+
expect(el).to.not.be.null;
14+
expect(el.text()).to.equal('hello world');
15+
});
16+
17+
it('can color', () => {
18+
const el = enzyme.shallow(React.createElement(Ansi, null, `hello ${GREEN_FG}world`));
19+
expect(el).to.not.be.null;
20+
expect(el.text()).to.equal('hello world');
21+
expect(el.html()).to.equal('<code><span>hello </span><span style="color:rgb(0, 187, 0);">world</span></code>');
22+
});
23+
24+
it('can nest', () => {
25+
const el = enzyme.shallow(React.createElement(Ansi, null, `hello ${GREEN_FG}wo${YELLOW_BG}rl${RESET}d`));
26+
expect(el).to.not.be.null;
27+
expect(el.text()).to.equal('hello world');
28+
expect(el.html()).to.equal('<code><span>hello </span><span style="color:rgb(0, 187, 0);">wo</span><span style="background-color:rgb(187, 187, 0);color:rgb(0, 187, 0);">rl</span><span>d</span></code>');
29+
});
30+
});

0 commit comments

Comments
 (0)