Basic usage

when called without any arguments

should not execute any callbacks
testParser.parser.parse();
assert.isFalse(testParser.start.called);
assert.isFalse(testParser.end.called);
assert.isFalse(testParser.data.called);

Simple examples

when called with string containing only a comment

should not execute any callbacks
var testParser = createTestParser();
testParser.parser.parse('<!-- foobar -->');
assert.isFalse(testParser.start.called);
assert.isFalse(testParser.end.called);
assert.isFalse(testParser.data.called);

when called with just one element

should execute start and end callbacks once
assert.equal(testParser.start.callCount, 1);
assert.equal(testParser.end.callCount, 1);
should execute start callback with tagname
assert.isTrue(testParser.start.calledWith('div'));

when called with just one element carrying attributes

should execute start callback with attribute string
var testParser = createTestParser();
testParser.parser.parse('<div bar="foo" foo="bar" foobar></div>');
assert.equal(testParser.start.firstCall.args[1], 'bar="foo" foo="bar" foobar');

when called with just one element containing text

should execute data callback once
assert.equal(testParser.data.callCount, 1);
should pass text content to data callback
assert.equal(testParser.data.firstCall.args[0], 'foobar');

when called with self-closing elements

should not execute end callbacks
assert.isFalse(testParser.end.called);
should execute start callback once per element
assert.equal(testParser.start.callCount, tagNames.length);
should execute start callback with correct tag names
var encounteredTags = testParser.start.args.map(function (args) {
    return args[0];
});
assert.sameMembers(encounteredTags, tagNames);

when called with script/style element

should execute the data callback with the entire style content
testParser.parser.parse('<style>body{font-size:16px;}h1{color:red;}</style>');
assert.equal(testParser.data.firstCall.args[0], 'body{font-size:16px;}h1{color:red;}');
should not break when markup is present in script tags
testParser.parser.parse('<script>var a="<p>test</p>";alert(a);</script>');
assert.equal(testParser.data.firstCall.args[0], 'var a="<p>test</p>";alert(a);');

when instantiated with parseAttributes=true

should execute start callback with arguments parsed as object
var testParser = createTestParser({ parseAttributes: true });
testParser.parser.parse('<div id="foo" class="bar baz" foo-bar-baz="baz"></div>');
var attrs = {
    id: 'foo',
    class: 'bar baz',
    fooBarBaz: 'baz'
};
assert.deepEqual(testParser.start.firstCall.args[1], attrs);