All files / src/dom domtokenlist.spec.ts

100% Statements 33/33
100% Branches 0/0
100% Functions 11/11
100% Lines 33/33
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 601x   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 { DOMTokenList } from 'dom/domtokenlist';
 
describe('DOMTokenList', function(){
 
	const expect = require('chai').expect;
 
	it('should split string into parts', () => {
		const list = new DOMTokenList('foo bar baz');
		expect(list).to.have.lengthOf(3);
		expect(Array.from(list)).to.deep.equal(['foo', 'bar', 'baz']);
	});
 
	it('should handle empty string', () => {
		const list = new DOMTokenList('');
		expect(list).to.have.lengthOf(0);
		expect(Array.from(list)).to.deep.equal([]);
	});
 
	it('should handle null', () => {
		const list = new DOMTokenList(null);
		expect(list).to.have.lengthOf(0);
		expect(Array.from(list)).to.deep.equal([]);
	});
 
	it('.value should return original value', () => {
		const list = new DOMTokenList('foo bar baz');
		expect(list.value).to.equal('foo bar baz');
	});
 
	describe('item()', () => {
 
		it('should return item by index', () => {
			const list = new DOMTokenList('foo bar baz');
			expect(list.item(1)).to.equal('bar');
		});
 
		it('should return undefined if out of range', () => {
			const list = new DOMTokenList('foo bar baz');
			expect(list.item(-1)).to.be.undefined;
			expect(list.item(3)).to.be.undefined;
		});
 
	});
 
	describe('contains()', () => {
 
		it('should return true if token exists', () => {
			const list = new DOMTokenList('foo bar baz');
			expect(list.contains('baz')).to.be.true;
		});
 
		it('should return false if token doesn\'t exists', () => {
			const list = new DOMTokenList('foo bar baz');
			expect(list.contains('spam')).to.be.false;
		});
 
	});
 
});