Skip to content

Commit 822ceff

Browse files
David Pazdavidmpaz
David Paz
authored andcommitted
Improve tests for compiling .tsx files
1 parent ae1bea3 commit 822ceff

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

fixtures/js/render2.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function render() {
2+
document.getElementById('wrapper').innerHTML = "<h1> Hello World!</h1>";
3+
}
4+
5+
export = render;

test/functional.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,32 @@ module.exports = {
601601
});
602602
});
603603

604+
it('When enabled, react JSX and TypeScript work nice together!', (done) => {
605+
const config = createWebpackConfig('www/build', 'dev');
606+
config.setPublicPath('/build');
607+
config.addEntry('main', ['./js/CoolReactComponent.jsx', './js/render2.tsx']);
608+
config.enableReactPreset();
609+
config.configureTypeScript(function(tsConfig) {
610+
tsConfig.compilerOptions = { 'jsx': 'preserve' };
611+
});
612+
613+
testSetup.runWebpack(config, (webpackAssert) => {
614+
// check that babel transformed the JSX
615+
webpackAssert.assertOutputFileContains(
616+
'main.js',
617+
'React.createElement'
618+
);
619+
620+
// and also ts-loader did its job
621+
webpackAssert.assertOutputFileContains(
622+
'main.js',
623+
'document.getElementById(\'wrapper\').innerHTML = "<h1> Hello World!</h1>";'
624+
);
625+
626+
done();
627+
});
628+
});
629+
604630
it('The output directory is cleaned between builds', (done) => {
605631
const config = createWebpackConfig('www/build', 'dev');
606632
config.setPublicPath('/build');

0 commit comments

Comments
 (0)