Add destroy function

This commit is contained in:
Keegan
2016-05-26 18:45:22 -07:00
parent b553094742
commit 70bb2e9d07
5 changed files with 150 additions and 7 deletions
+44
View File
@@ -254,6 +254,50 @@ describe('ClayConfig', function() {
});
});
describe('.destroy().', function() {
it('Destroys all the items on the page and in the items array', function() {
var clayConfig = fixtures.clayConfig(['input', 'text', 'input'], false);
clayConfig.build();
clayConfig.destroy();
// this should throw because the config has not been built yet
assert.throws(clayConfig.getAllItems);
// there should be no DOM inside the container
assert.strictEqual(clayConfig.$rootContainer[0].children.length, 0);
});
it('dispatches the BEFORE_DESTROY event at the right time', function(done) {
var clayConfig = fixtures.clayConfig(['input', 'text', 'input'], false);
clayConfig.on(clayConfig.EVENTS.BEFORE_DESTROY, function() {
assert.strictEqual(clayConfig.getAllItems().length, 3);
done();
});
clayConfig.build();
clayConfig.destroy();
assert.strictEqual(clayConfig.getAllItems().length, 0);
});
it('dispatches the AFTER_DESTROY event at the right time', function(done) {
var clayConfig = fixtures.clayConfig(['input', 'text', 'input'], false);
clayConfig.on(clayConfig.EVENTS.AFTER_DESTROY, function() {
// this should throw because the config has not been built yet
assert.throws(clayConfig.getAllItems);
done();
});
clayConfig.build();
assert.strictEqual(clayConfig.getAllItems().length, 3);
clayConfig.destroy();
});
});
describe('.build()', function() {
it('dispatches the BEFORE_BUILD event at the right time', function(done) {
var clayConfig = fixtures.clayConfig(['input', 'text', 'input'], false);