All files / src/rules element-permitted-content.spec.ts

100% Statements 26/26
100% Branches 0/0
100% Functions 8/8
100% Lines 26/26
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 491x   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 element-permitted-content', function(){
 
	const expect = require('chai').expect;
 
	let htmlvalidate: HtmlValidate;
 
	before(function(){
		htmlvalidate = new HtmlValidate({
			rules: {'element-permitted-content': 'error'},
		});
	});
 
	it('should report error when @flow is child of @phrasing', function(){
		const report = htmlvalidate.validateString('<span><div></div></span>');
		expect(report).to.be.invalid;
		expect(report).to.have.error('element-permitted-content', 'Element <div> is not permitted as content in <span>');
	});
 
	it('should not report error when phrasing a-element is child of @phrasing', function(){
		const report = htmlvalidate.validateString('<span><a><span></span></a></span>');
		expect(report).to.be.valid;
	});
 
	it('should report error when non-phrasing a-element is child of @phrasing', function(){
		const report = htmlvalidate.validateString('<span><a><div></div></a></span>');
		expect(report).to.be.invalid;
		expect(report).to.have.error('element-permitted-content', 'Element <div> is not permitted as content in <span>');
	});
 
	it('should report error when label contains non-phrasing', function(){
		const report = htmlvalidate.validateString('<label><div>foobar</div></label>');
		expect(report).to.be.invalid;
		expect(report).to.have.error('element-permitted-content', 'Element <div> is not permitted as content in <label>');
	});
 
	it('should handle missing meta entry (child)', function(){
		const report = htmlvalidate.validateString('<p><foo>foo</foo></p>');
		expect(report).to.be.valid;
	});
 
	it('should handle missing meta entry (descendant)', function(){
		const report = htmlvalidate.validateString('<th><foo>foo</foo></th>');
		expect(report).to.be.valid;
	});
 
});