Commit 32d88db6 authored by André Luís's avatar André Luís

Fix autosize using waitForCSSLoaded

parent daecc94d
import Autosize from 'autosize'; import Autosize from 'autosize';
import { waitForCSSLoaded } from '../helpers/startup_css_helper';
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
const autosizeEls = document.querySelectorAll('.js-autosize'); waitForCSSLoaded(() => {
const autosizeEls = document.querySelectorAll('.js-autosize');
Autosize(autosizeEls); Autosize(autosizeEls);
Autosize.update(autosizeEls); Autosize.update(autosizeEls);
autosizeEls.forEach(el => el.classList.add('js-autosize-initialized'));
});
}); });
import $ from 'jquery';
import '~/behaviors/autosize'; import '~/behaviors/autosize';
function load() { function load() {
$(document).trigger('load'); document.dispatchEvent(new Event('DOMContentLoaded'));
} }
jest.mock('~/helpers/startup_css_helper', () => {
return {
waitForCSSLoaded: jest.fn().mockImplementation(cb => cb.apply()),
};
});
describe('Autosize behavior', () => { describe('Autosize behavior', () => {
beforeEach(() => { beforeEach(() => {
setFixtures('<textarea class="js-autosize" style="resize: vertical"></textarea>'); setFixtures('<textarea class="js-autosize"></textarea>');
}); });
it('does not overwrite the resize property', () => { it('is applied to the textarea', () => {
load(); load();
expect($('textarea')).toHaveCss({ const textarea = document.querySelector('textarea');
resize: 'vertical', expect(textarea.classList).toContain('js-autosize-initialized');
});
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment