|
| 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