-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
94 lines (74 loc) · 2.14 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const babel = require('babel-core');
const plugin = require('./index');
const classPropertyTransformer = require('babel-plugin-transform-class-properties');
it('adds variable name as label to console.log argument', () => {
const example = `
const a = 'wut';
console.log(a);
`;
const code = babel.transform(example, { plugins: [plugin] }).code;
expect(code).toMatchSnapshot();
});
it('adds correct label when printing out instance properties', () => {
const example = `
this.a = 'wut';
console.log(this.a);
`;
const code = babel.transform(example, { plugins: [plugin] }).code;
expect(code).toMatchSnapshot();
});
it('adds label when printing out functions', () => {
const example = `
function a () { console.log('hi'); };
console.log(a);
`;
const code = babel.transform(example, { plugins: [plugin] }).code;
expect(code).toMatchSnapshot();
});
it('adds concatenated variable name as label to console.log argument', () => {
const example = `
const a = 'wut';
const b = 'wut again';
const c = 'wut once again';
console.log(a, b, c);
`;
const code = babel.transform(example, { plugins: [plugin] }).code;
expect(code).toMatchSnapshot();
});
it('does not add label if variables are not used', () => {
const example = `
console.log('wut');
`;
const code = babel.transform(example, { plugins: [plugin] }).code;
expect(code).toMatchSnapshot();
});
it('works when printing variables pointing to objects', () => {
const example = `
const wut = { a: 1 };
console.log(wut);
`;
const code = babel.transform(example, { plugins: [plugin] }).code;
expect(code).toMatchSnapshot();
});
it('works when printing variables pointing to functions', () => {
const example = `
const wut = function () {
console.log('hi');
}
console.log(wut);
`;
const code = babel.transform(example, { plugins: [plugin] }).code;
expect(code).toMatchSnapshot();
});
it('works inside class methods', () => {
const example = `
class A {
componentWillReceiveProps (nextProps) {
console.log(this.props);
console.log(nextProps);
}
}
`;
const code = babel.transform(example, { plugins: [plugin] }).code;
expect(code).toMatchSnapshot();
});