|
2 | 2 | /* eslint-disable no-unused-expressions */ |
3 | 3 |
|
4 | 4 | import React from 'react'; |
| 5 | +import ReactDOM from 'react-dom'; |
5 | 6 | import TestUtils from 'react-addons-test-utils'; |
6 | 7 | import Highlight from '../Highlight'; |
7 | 8 | import { expect } from 'chai'; |
8 | 9 | import hjs from 'highlight.js'; |
9 | 10 | import sinon from 'sinon'; |
10 | 11 |
|
11 | | -describe('Button', () => { |
12 | | - it('has correct label', () => { |
13 | | - const highlightAuto = sinon.spy(hjs, 'highlightAuto'); |
14 | | - TestUtils.renderIntoDocument( |
15 | | - <Highlight>test</Highlight> |
16 | | - ); |
| 12 | +describe('Highlight', () => { |
| 13 | + describe('no languages', () => { |
| 14 | + it('calls correct highlightCall', () => { |
| 15 | + const highlightAuto = sinon.spy(hjs, 'highlightAuto'); |
| 16 | + TestUtils.renderIntoDocument( |
| 17 | + <Highlight>test</Highlight> |
| 18 | + ); |
| 19 | + |
| 20 | + expect(highlightAuto).to.have.been.calledOnce; |
| 21 | + expect(highlightAuto).to.have.been.calledWith('test'); |
| 22 | + |
| 23 | + highlightAuto.restore(); |
| 24 | + }); |
| 25 | + }); |
17 | 26 |
|
18 | | - expect(highlightAuto).to.have.been.calledOnce; |
19 | | - expect(highlightAuto).to.have.been.calledWith('test'); |
| 27 | + describe('one language', () => { |
| 28 | + it('calls correct highlightCall', () => { |
| 29 | + const highlight = sinon.spy(hjs, 'highlight'); |
| 30 | + TestUtils.renderIntoDocument( |
| 31 | + <Highlight languages={['js']}>test</Highlight> |
| 32 | + ); |
| 33 | + |
| 34 | + expect(highlight).to.have.been.calledOnce; |
| 35 | + expect(highlight).to.have.been.calledWith('js', 'test'); |
| 36 | + |
| 37 | + highlight.restore(); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + describe('multiple languages', () => { |
| 42 | + it('calls correct highlightCall', () => { |
| 43 | + const highlightAuto = sinon.spy(hjs, 'highlightAuto'); |
| 44 | + TestUtils.renderIntoDocument( |
| 45 | + <Highlight languages={['js', 'html']}>test</Highlight> |
| 46 | + ); |
| 47 | + |
| 48 | + expect(highlightAuto).to.have.been.calledOnce; |
| 49 | + expect(highlightAuto).to.have.been.calledWith('test', ['js', 'html']); |
| 50 | + |
| 51 | + highlightAuto.restore(); |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + it('className is passed through', () => { |
| 56 | + const component = TestUtils.renderIntoDocument( |
| 57 | + <Highlight className="foobla">test</Highlight> |
| 58 | + ); |
| 59 | + const domElement = ReactDOM.findDOMNode(component); |
20 | 60 |
|
21 | | - highlightAuto.restore(); |
| 61 | + expect(domElement.children[0].classList.contains('foobla')).to.equal.true; |
22 | 62 | }); |
23 | 63 | }); |
0 commit comments