chore(auto-submit-button): implemented destroy in auto-submit-button

This commit is contained in:
Johannes Eder 2021-07-02 15:40:53 +02:00 committed by Sarah Vaupel
parent 780a5f7ce1
commit 3e01c8d910
2 changed files with 31 additions and 1 deletions

View File

@ -9,8 +9,10 @@ const AUTO_SUBMIT_BUTTON_HIDDEN_CLASS = 'hidden';
selector: AUTO_SUBMIT_BUTTON_UTIL_SELECTOR,
})
export class AutoSubmitButton {
_element;
constructor(element) {
this._element = element;
if (!element) {
throw new Error('Auto Submit Button utility needs to be passed an element!');
}
@ -24,6 +26,7 @@ export class AutoSubmitButton {
}
destroy() {
// TODO
this._element.classList.remove(AUTO_SUBMIT_BUTTON_INITIALIZED_CLASS);
this._element.classList.remove(AUTO_SUBMIT_BUTTON_HIDDEN_CLASS);
}
}

View File

@ -0,0 +1,27 @@
import { AutoSubmitButton, AUTO_SUBMIT_BUTTON_INITIALIZED_CLASS, AUTO_SUBMIT_BUTTON_HIDDEN_CLASS } from './auto-submit-button.js';
describe('Auto-submit-button', () => {
let autoSubmitButton;
beforeEach(() => {
const element = document.createElement('div');
autoSubmitButton = new AutoSubmitButton(element);
});
it('should create', () => {
expect(autoSubmitButton).toBeTruthy();
});
it('should destory auto-submit-button', () => {
autoSubmitButton.destroy();
expect(autoSubmitButton._element.classList).not.toContain(AUTO_SUBMIT_BUTTON_INITIALIZED_CLASS);
expect(autoSubmitButton._element.classList).not.toContain(AUTO_SUBMIT_BUTTON_HIDDEN_CLASS);
});
it('should throw if called without an element', () => {
expect(() => {
new AutoSubmitButton();
}).toThrow();
});
});