react / wstein / node_modules / react / node_modules / envify / node_modules / jstransform / visitors / __tests__ / es6-object-short-notation-visitors-test.js
80551 views/**1* Copyright 2013 Facebook, Inc.2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*/1516/**17* @emails [email protected]18*/1920/*jshint evil:true*/2122require('mock-modules').autoMockOff();2324describe('es6-object-short-notation-visitors', function() {25var transformFn;2627var destructuringVisitors;28var shortObjectsVisitors;2930var visitors;3132beforeEach(function() {33require('mock-modules').dumpCache();34transformFn = require('../../src/jstransform').transform;3536shortObjectsVisitors = require('../es6-object-short-notation-visitors').visitorList;37destructuringVisitors = require('../es6-destructuring-visitors').visitorList;3839visitors = shortObjectsVisitors.concat(destructuringVisitors);40});4142function transform(code) {43return transformFn(visitors, code).code;44}4546function expectTransform(code, result) {47expect(transform(code)).toEqual(result);48}4950// Functional tests.5152it('should transform short notation and return 5', function() {53var code = transform([54'(function(x, y) {',55' var data = {x, y};',56' return data.x + data.y;',57'})(2, 3);'58].join('\n'));5960expect(eval(code)).toEqual(5);61});6263it('should transform work with destructuring and return 10', function() {64var code = transform([65'var x = 5, y = 5;',66'(function({x, y}) {',67' var data = {x, y};',68' return data.x + data.y;',69'})({x, y});'70].join('\n'));7172expect(eval(code)).toEqual(10);73});7475// Source code tests.76it('should transform simple short notation', function() {7778// Should transform simple short notation.79expectTransform(80'function foo(x, y) { return {x, y}; }',81'function foo(x, y) { return {x:x, y:y}; }'82);8384// Should preserve lines transforming ugly code.85expectTransform([86'function',87'',88'foo (',89' x,',90' y',91'',92')',93'',94' {',95' return {',96' x,',97' y};',98'}'99].join('\n'), [100'function',101'',102'foo (',103' x,',104' y',105'',106')',107'',108' {',109' return {',110' x:x,',111' y:y};',112'}'113].join('\n'));114});115116});117118119120121