require 'spec_helper'
describe "JSX" do
let(:filename) { 'test.jsx' }
def setup_filetype
vim.set(:filetype, 'javascriptreact')
vim.set(:expandtab)
vim.set(:shiftwidth, 2)
end
after :each do
vim.command('silent! unlet g:splitjoin_html_attributes_bracket_on_new_line')
end
describe "self-closing tags" do
specify "basic" do
set_file_contents ';'
setup_filetype
vim.search 'Button'
split
remove_indentation
assert_file_contents <<~EOF
;
EOF
join
assert_file_contents ';'
end
specify "joining on a single line" do
set_file_contents 'let button = ;'
setup_filetype
vim.search 'Button'
join
remove_indentation
assert_file_contents <<~EOF
let button = ;
EOF
end
specify "with attributes" do
set_file_contents ';'
setup_filetype
vim.search 'Button'
split
remove_indentation
assert_file_contents <<~EOF
;
EOF
split
remove_indentation
assert_file_contents <<~EOF
;
EOF
vim.search ';
EOF
join
remove_indentation
assert_file_contents ';'
end
end
describe "JSX expressions" do
specify "self-closing tag with a let statement" do
set_file_contents 'let button = ;'
setup_filetype
vim.search 'Button'
split
remove_indentation
assert_file_contents <<~EOF
let button = (
);
EOF
vim.search('button = \zs(')
join
assert_file_contents 'let button = ;'
end
specify "simple tag with a return statement" do
set_file_contents <<~EOF
function button() {
return ;
}
EOF
setup_filetype
vim.search '
);
}
EOF
vim.search('return \zs(')
join
assert_file_contents <<~EOF
function button() {
return ;
}
EOF
end
specify "tag with attributes in a lambda" do
set_file_contents '() => '
setup_filetype
vim.search '