UNPKG

1.28 kBJavaScriptView Raw
1const babel = require('@babel/core');
2const { wrap } = require('jest-snapshot-serializer-raw');
3const preset = require('..');
4
5function transform(input, options = {}) {
6 return wrap(
7 babel.transform(input, {
8 filename: 'file.ts',
9 babelrc: false,
10 presets: [preset],
11 sourceMaps: true,
12 }).code
13 );
14}
15
16it('optional-chaining', () => {
17 expect(
18 transform(`
19 foo?.bar;
20 `)
21 ).toMatchSnapshot();
22});
23it('nullish-coalescing', () => {
24 expect(
25 transform(`
26 var foo = object.foo ?? "default";
27 `)
28 ).toMatchSnapshot();
29});
30it('class-properties', () => {
31 expect(
32 transform(`
33 class Bork {
34 //Property initializer syntax
35 instanceProperty = "bork";
36 boundFunction = () => {
37 return this.instanceProperty;
38 };
39
40 //Static class properties
41 static staticProperty = "babelIsCool";
42 static staticFunction = function() {
43 return Bork.staticProperty;
44 };
45 }
46 `)
47 ).toMatchSnapshot();
48});
49it('preset-typescript', () => {
50 expect(
51 transform(`
52 const x: number = 0;
53 `)
54 ).toMatchSnapshot();
55});
56it('plugin-transform-modules-commonjs', () => {
57 expect(
58 transform(`
59 export default 42;
60 `)
61 ).toMatchSnapshot();
62});