All files / src/rules close-order.spec.ts

100% Statements 32/32
100% Branches 0/0
100% Functions 10/10
100% Lines 32/32
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 591x   1x   1x       1x 1x         1x 1x 1x     1x 1x 1x     1x 1x 1x     1x 1x 1x     1x 1x 1x     1x 1x 1x 1x     1x 1x 1x 1x     1x 1x 1x 1x        
import HtmlValidate from '../htmlvalidate';
 
describe('rule close-order', function(){
 
	const expect = require('chai').expect;
 
	let htmlvalidate: HtmlValidate;
 
	before(function(){
		htmlvalidate = new HtmlValidate({
			rules: {'close-order': 'error'},
		});
	});
 
	it('should not report when elements are correct in wrong order', function(){
		const report = htmlvalidate.validateString('<div></div>');
		expect(report).to.be.valid;
	});
 
	it('should not report for self-closing element', function(){
		const report = htmlvalidate.validateString('<div><input/></div>');
		expect(report).to.be.valid;
	});
 
	it('should not report for self-closing element with attribute', function(){
		const report = htmlvalidate.validateString('<div><input required/></div>');
		expect(report).to.be.valid;
	});
 
	it('should not report for void element', function(){
		const report = htmlvalidate.validateString('<div><input></div>');
		expect(report).to.be.valid;
	});
 
	it('should not report for void element with attribute', function(){
		const report = htmlvalidate.validateString('<div><input required></div>');
		expect(report).to.be.valid;
	});
 
	it('should report error when elements are closed in wrong order', function(){
		const report = htmlvalidate.validateString('<div></p>');
		expect(report).to.be.invalid;
		expect(report).to.have.error('close-order', 'Mismatched close-tag, expected \'</div>\' but found \'</p>\'.');
	});
 
	it('should report error when element is missing close tag', function(){
		const report = htmlvalidate.validateString('<div>');
		expect(report).to.be.invalid;
		expect(report).to.have.error('close-order', 'Missing close-tag, expected \'</div>\' but document ended before it was found.');
	});
 
	it('should report error when element is missing opening tag', function(){
		const report = htmlvalidate.validateString('</div>');
		expect(report).to.be.invalid;
		expect(report).to.have.error('close-order', 'Unexpected close-tag, expected opening tag.');
	});
 
});