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

100% Statements 42/42
100% Branches 0/0
100% Functions 17/17
100% Lines 42/42
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 931x   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 attr-quotes', function(){
 
	const expect = require('chai').expect;
 
	let htmlvalidate: HtmlValidate;
 
	describe('with double-quote option', function(){
 
		before(function(){
			htmlvalidate = new HtmlValidate({
				rules: {'attr-quotes': ['error', {style: "double"}]},
			});
		});
 
		it('should not report when attributes use double quotes', function(){
			const report = htmlvalidate.validateString('<div foo="bar"></div>');
			expect(report).to.be.valid;
		});
 
		it('should report error when attributes use single quotes', function(){
			const report = htmlvalidate.validateString('<div foo=\'bar\'></div>');
			expect(report).to.be.invalid;
			expect(report).to.have.error('attr-quotes', 'Attribute "foo" used \' instead of expected "');
		});
 
	});
 
	describe('with single-quote option', function(){
 
		before(function(){
			htmlvalidate = new HtmlValidate({
				rules: {'attr-quotes': ['error', {style: "single"}]},
			});
		});
 
		it('should report error when attributes use double quotes', function(){
			const report = htmlvalidate.validateString('<div foo="bar"></div>');
			expect(report).to.be.invalid;
			expect(report).to.have.error('attr-quotes', 'Attribute "foo" used " instead of expected \'');
		});
 
		it('should not report when attributes use single quotes', function(){
			const report = htmlvalidate.validateString('<div foo=\'bar\'></div>');
			expect(report).to.be.valid;
		});
 
	});
 
	describe('with unquoted allowed', function(){
 
		before(function(){
			htmlvalidate = new HtmlValidate({
				rules: {'attr-quotes': ['error', {style: "double", unquoted: true}]},
			});
		});
 
		it('should not report when attributes is using quotes', function(){
			const report = htmlvalidate.validateString('<div foo="bar"></div>');
			expect(report).to.be.valid;
		});
 
		it('should not report error when attribute value is unquoted', function(){
			const report = htmlvalidate.validateString('<div foo=5></div>');
			expect(report).to.be.valid;
		});
 
	});
 
	describe('with unquoted disabled', function(){
 
		before(function(){
			htmlvalidate = new HtmlValidate({
				rules: {'attr-quotes': ['error', {style: "double", unquoted: false}]},
			});
		});
 
		it('should not report when attributes is using quotes', function(){
			const report = htmlvalidate.validateString('<div foo="bar"></div>');
			expect(report).to.be.valid;
		});
 
		it('should report error when attribute value is unquoted', function(){
			const report = htmlvalidate.validateString('<div foo=5></div>');
			expect(report).to.be.invalid;
			expect(report).to.have.error('attr-quotes', 'Attribute "foo" using unquoted value');
		});
 
	});
 
});