|
1 | 1 | var parser = require('..');
|
| 2 | +var parserWithMockedDeps = require('rewire')('..'); |
2 | 3 | var describe = require('mocha').describe;
|
3 | 4 | var it = require('mocha').it;
|
4 |
| -var expect = require('chai').expect; |
| 5 | +var beforeEach = require('mocha').beforeEach; |
| 6 | +var chai = require('chai'); |
| 7 | +var sinon = require('sinon'); |
| 8 | +var expect = chai.expect; |
| 9 | +chai.use(require('sinon-chai')); |
5 | 10 |
|
6 | 11 | describe('PostHTML-Parser test', function() {
|
| 12 | + describe('Call signatures', function() { |
| 13 | + var customOptions = {lowerCaseTags: false, lowerCaseAttributeNames: false}; |
| 14 | + var MockedHtmlParser2; |
| 15 | + var parserSpy; |
| 16 | + |
| 17 | + beforeEach(function() { |
| 18 | + // jscs:disable requireFunctionDeclarations |
| 19 | + MockedHtmlParser2 = function() {}; |
| 20 | + MockedHtmlParser2.prototype = { |
| 21 | + write: function() {}, |
| 22 | + end: function() {} |
| 23 | + }; |
| 24 | + // jscs:enable requireFunctionDeclarations |
| 25 | + |
| 26 | + // Create spy on mocked htmlparser2 to collect call stats |
| 27 | + parserSpy = sinon.spy(MockedHtmlParser2); |
| 28 | + |
| 29 | + // Replace real htmlparser2 dependency of posthtml-parser with mocked |
| 30 | + parserWithMockedDeps.__set__({ |
| 31 | + htmlparser: {Parser: parserSpy} |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should use default options when called with 1 param', function() { |
| 36 | + parserWithMockedDeps(''); |
| 37 | + expect(parserSpy.firstCall.args[1]).to.eql(parser.defaultOptions); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should use custom options when called with 2 params', function() { |
| 41 | + parserWithMockedDeps('', customOptions); |
| 42 | + expect(parserSpy.firstCall.args[1]).to.eql(customOptions); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should use custom params when called as factory function', function() { |
| 46 | + var factory = parserWithMockedDeps(customOptions); |
| 47 | + expect(factory).to.be.a('function'); |
| 48 | + expect(factory('')).to.be.an('array'); |
| 49 | + expect(parserSpy.firstCall.args[1]).to.eql(customOptions); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
7 | 53 | it('should be parse doctype in uppercase', function() {
|
8 | 54 | expect(parser('<!DOCTYPE html>')).to.eql(['<!DOCTYPE html>']);
|
9 | 55 | });
|
|
0 commit comments