All files / src/rules void.spec.ts

100% Statements 52/52
100% Branches 0/0
100% Functions 20/20
100% Lines 52/52
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 1091x   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 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 void', function() {
 
	const expect = require('chai').expect;
 
	let htmlvalidate: HtmlValidate;
 
	describe('default', function(){
 
		before(function() {
			htmlvalidate = new HtmlValidate({
				rules: { 'void': 'error' },
			});
		});
 
		it('should not report when void element omitted end tag', function() {
			const report = htmlvalidate.validateString('<input>');
			expect(report).to.be.valid;
		});
 
		it('should report when void element is self-closed', function() {
			const report = htmlvalidate.validateString('<input/>');
			expect(report).to.be.invalid;
			expect(report).to.have.error('void', 'Expected omitted end tag <input> instead of self-closing element <input/>');
		});
 
		it('should not report when non-void element has end tag', function() {
			const report = htmlvalidate.validateString('<div></div>');
			expect(report).to.be.valid;
		});
 
		it('should not report when xml namespaces is used', function() {
			const report = htmlvalidate.validateString('<xi:include/>');
			expect(report).to.be.valid;
		});
 
		it('should report error when non-void element omitted end tag', function(){
			const report = htmlvalidate.validateString('<div/>');
			expect(report).to.be.invalid;
			expect(report).to.have.error('void', 'End tag for <div> must not be omitted');
		});
 
	});
 
	describe('configured with style="omit"', function(){
 
		before(function() {
			htmlvalidate = new HtmlValidate({
				rules: { 'void': ['error', {style: 'omit'}]},
			});
		});
 
		it('should not report when void element omits end tag', function() {
			const report = htmlvalidate.validateString('<input>');
			expect(report).to.be.valid;
		});
 
		it('should report when void element is self-closed', function() {
			const report = htmlvalidate.validateString('<input/>');
			expect(report).to.be.invalid;
			expect(report).to.have.error('void', 'Expected omitted end tag <input> instead of self-closing element <input/>');
		});
 
	});
 
	describe('configured with style="selfclose"', function(){
 
		before(function() {
			htmlvalidate = new HtmlValidate({
				rules: { 'void': ['error', {style: 'selfclose'}]},
			});
		});
 
		it('should report when void element omits end tag', function() {
			const report = htmlvalidate.validateString('<input>');
			expect(report).to.be.invalid;
			expect(report).to.have.error('void', 'Expected self-closing element <input/> instead of omitted end-tag <input>');
		});
 
		it('should not report when void element is self-closed', function() {
			const report = htmlvalidate.validateString('<input/>');
			expect(report).to.be.valid;
		});
 
	});
 
	describe('configured with style="any"', function(){
 
		before(function() {
			htmlvalidate = new HtmlValidate({
				rules: { 'void': ['error', {style: 'any'}]},
			});
		});
 
		it('should not report when void element omits end tag', function() {
			const report = htmlvalidate.validateString('<input>');
			expect(report).to.be.valid;
		});
 
		it('should not report when void element is self-closed', function() {
			const report = htmlvalidate.validateString('<input/>');
			expect(report).to.be.valid;
		});
 
	});
 
});