UNPKG

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