All files / src/rules input-missing-label.spec.ts

100% Statements 15/15
100% Branches 0/0
100% Functions 5/5
100% Lines 15/15
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 321x   1x   1x       1x 1x         1x 1x 1x     1x 1x 1x     1x 1x 1x 1x        
import HtmlValidate from '../htmlvalidate';
 
describe('rule input-missing-label', function() {
 
	const expect = require('chai').expect;
 
	let htmlvalidate: HtmlValidate;
 
	before(function() {
		htmlvalidate = new HtmlValidate({
			rules: { 'input-missing-label': 'error' },
		});
	});
 
	it('should not report when input id has matching label', function() {
		const report = htmlvalidate.validateString('<label for="foo">foo</label><input id="foo"/>');
		expect(report).to.be.valid;
	});
 
	it('should not report when input is nested inside label', function() {
		const report = htmlvalidate.validateString('<label>foo <input/></label>');
		expect(report).to.be.valid;
	});
 
	it('should report when label is missing label', function() {
		const report = htmlvalidate.validateString('<input/>');
		expect(report).to.be.invalid;
		expect(report).to.have.error('input-missing-label', 'Input element does not have a label');
	});
 
});