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

Fix autosize using waitForCSSLoaded

parent daecc94d
import Autosize from 'autosize';
import { waitForCSSLoaded } from '../helpers/startup_css_helper';
document.addEventListener('DOMContentLoaded', () => {
const autosizeEls = document.querySelectorAll('.js-autosize');
waitForCSSLoaded(() => {
const autosizeEls = document.querySelectorAll('.js-autosize');
Autosize(autosizeEls);
Autosize.update(autosizeEls);
Autosize(autosizeEls);
Autosize.update(autosizeEls);
autosizeEls.forEach(el => el.classList.add('js-autosize-initialized'));
});
});
import $ from 'jquery';
import '~/behaviors/autosize';
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', () => {
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();
expect($('textarea')).toHaveCss({
resize: 'vertical',
});
const textarea = document.querySelector('textarea');
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