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

100% Statements 22/22
100% Branches 0/0
100% Functions 6/6
100% Lines 22/22
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 411x   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-attr', function(){
 
	const expect = require('chai').expect;
 
	let htmlvalidate: HtmlValidate;
 
	before(function(){
		htmlvalidate = new HtmlValidate({
			rules: {'close-attr': 'error'},
		});
	});
 
	it('should not report when close tags are correct', function(){
		const report = htmlvalidate.validateString('<div></div>');
		expect(report).to.be.valid;
	});
 
	it('should not report errors on self-closing tags', function(){
		const report = htmlvalidate.validateString('<input required/>');
		expect(report).to.be.valid;
	});
 
	it('should not report errors on void tags', function(){
		const report = htmlvalidate.validateString('<input required>');
		expect(report).to.be.valid;
	});
 
	it('should report when close tags contains attributes', function(){
		const html = "<p></p foo=\"bar\"><p></p foo='bar'><p></p foo>";
		const report = htmlvalidate.validateString(html);
		expect(report).to.be.invalid;
		expect(report.results[0].messages, "report should contain 3 errors").to.have.lengthOf(3);
		expect(report.results[0].messages[0].ruleId, "reported error should be close-attr").to.equal('close-attr');
		expect(report.results[0].messages[1].ruleId, "reported error should be close-attr").to.equal('close-attr');
		expect(report.results[0].messages[2].ruleId, "reported error should be close-attr").to.equal('close-attr');
	});
 
});