All files / src/rules button-type.spec.ts

100% Statements 22/22
100% Branches 0/0
100% Functions 7/7
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 41 42 431x   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 button-type', function(){
 
	const expect = require('chai').expect;
 
	let htmlvalidate: HtmlValidate;
 
	before(function(){
		htmlvalidate = new HtmlValidate({
			rules: {'button-type': 'error'},
		});
	});
 
	it('should not report when button has type="submit"', function(){
		const report = htmlvalidate.validateString('<button type="submit"></button>');
		expect(report).to.be.valid;
	});
 
	it('should not report when button has type="button"', function(){
		const report = htmlvalidate.validateString('<button type="button"></button>');
		expect(report).to.be.valid;
	});
 
	it('should not report when button has type="reset"', function(){
		const report = htmlvalidate.validateString('<button type="reset"></button>');
		expect(report).to.be.valid;
	});
 
	it('should report error when type attribute is missing', function(){
		const report = htmlvalidate.validateString('<button></button>');
		expect(report).to.be.invalid;
		expect(report).to.have.error('button-type', 'Button is missing type attribute');
	});
 
	it('should report error when type attribute is invalid', function(){
		const report = htmlvalidate.validateString('<button type="foo"></button>');
		expect(report).to.be.invalid;
		expect(report).to.have.error('button-type', 'Button has invalid type "foo"');
	});
 
});