Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81164 views
1
/**
2
* Copyright 2013-2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @emails react-core
10
*/
11
"use strict";
12
13
require('mock-modules').autoMockOff();
14
15
var transformAll = require('../../syntax.js').transformAll;
16
17
function transform(source) {
18
return transformAll(source, {}, ['allocate']);
19
}
20
21
describe('react displayName jsx', function() {
22
23
it('should only inject displayName if missing', function() {
24
var code = [
25
'"use strict";',
26
'var Whateva = React.createClass({',
27
' displayName: "Whateva",',
28
' render: function() {',
29
' return null;',
30
' }',
31
'});'
32
].join('\n');
33
34
var result = [
35
'"use strict";',
36
'var Whateva = React.createClass({',
37
' displayName: "Whateva",',
38
' render: function() {',
39
' return null;',
40
' }',
41
'});'
42
].join('\n');
43
44
expect(transform(code).code).toEqual(result);
45
});
46
47
it('should inject displayName in simple assignment', () => {
48
var code = [
49
'var Component = React.createClass({',
50
' render: function() {',
51
' return null;',
52
' }',
53
'});'
54
].join('\n');
55
56
var result = [
57
'var Component = React.createClass({displayName: "Component",',
58
' render: function() {',
59
' return null;',
60
' }',
61
'});'
62
].join('\n');
63
64
expect(transform(code).code).toEqual(result);
65
});
66
67
it('should inject displayName in simple assignment without var', () => {
68
var code = [
69
'var Component;',
70
'Component = React.createClass({',
71
' render: function() {',
72
' return null;',
73
' }',
74
'});'
75
].join('\n');
76
77
var result = [
78
'var Component;',
79
'Component = React.createClass({displayName: "Component",',
80
' render: function() {',
81
' return null;',
82
' }',
83
'});'
84
].join('\n');
85
86
expect(transform(code).code).toEqual(result);
87
});
88
89
it('should inject displayName in property assignment', () => {
90
var code = [
91
'exports.Component = React.createClass({',
92
' render: function() {',
93
' return null;',
94
' }',
95
'});'
96
].join('\n');
97
98
var result = [
99
'exports.Component = React.createClass({displayName: "Component",',
100
' render: function() {',
101
' return null;',
102
' }',
103
'});'
104
].join('\n');
105
106
expect(transform(code).code).toEqual(result);
107
});
108
109
it('should inject displayName in object declaration', () => {
110
var code = [
111
'exports = {',
112
' Component: React.createClass({',
113
' render: function() {',
114
' return null;',
115
' }',
116
' })',
117
'};'
118
].join('\n');
119
120
var result = [
121
'exports = {',
122
' Component: React.createClass({displayName: "Component",',
123
' render: function() {',
124
' return null;',
125
' }',
126
' })',
127
'};'
128
].join('\n');
129
130
expect(transform(code).code).toEqual(result);
131
});
132
133
});
134
135