document[bracket] query tests
by James Greene
HTML
<script src="//rawgithub.com/LearnBoost/expect.js/0.2.0/expect.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mocha/1.13.0/mocha.js"></script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/mocha/1.13.0/mocha.css">
<div id="mocha"></div>
<object id="a">
<embed name="a"></embed>
</object>
<object id="b">
<embed name="b"></embed>
</object>
<object id="b">
<embed name="b"></embed>
</object>
JavaScript
mocha.setup('bdd');
// In Chrome stable (30), this returns 1 item as a DOM node (1 `embed` tag named "a")
// In Chrome Canary (33), this returns 2 items as an HTMLCollection (the 1 `object` tag and 1 `embed` tag IDed/named "a")
describe('document["a"]', function () {
it('should return 1 element', function () {
var result = document["a"];
expect(result).not.to.have.property('length');
expect(result).to.have.property('tagName');
expect(result.tagName).to.match(/^(?:object|embed)$/i);
});
});
// In Chrome stable (30), this returns 2 items as an HTMLCollection (2 `embed` tags named "b")
// In Chrome Canary (33), this returns 4 items as an HTMLCollection (the 2 `object` tags and 2 `embed` tags IDed/named "b", in document order)
describe('document["b"]', function () {
it('should return 2 elements', function () {
var result = document["b"];
expect(result).to.have.property('length', 2);
expect(result).not.to.have.property('tagName');
expect(result[0].tagName).to.match(/^(?:object|embed)$/i);
expect(result[1].tagName).to.match(/^(?:object|embed)$/i);
});
});
mocha.checkLeaks();
mocha.globals(['expect']);
mocha.run();