react / wstein / node_modules / react / node_modules / envify / node_modules / jstransform / visitors / __tests__ / es6-es7-object-integration-test.js
80551 views/**1* @emails [email protected] [email protected]2*/34/*jshint evil:true*/56require('mock-modules').autoMockOff();78describe('es6-es7-object-integration-test', function() {9var transformFn;1011var visitors;1213// These are placeholder variables in scope that we can use to assert that a14// specific variable reference was passed, rather than an object clone of it.15var x = 123456;16var z = 345678;1718beforeEach(function() {19require('mock-modules').dumpCache();20transformFn = require('../../src/jstransform').transform;2122var conciseMethodVisitors = require('../es6-object-concise-method-visitors').visitorList;23var shortObjectsVisitors = require('../es6-object-short-notation-visitors').visitorList;24var spreadPropertyVisitors = require('../es7-spread-property-visitors').visitorList;2526visitors = spreadPropertyVisitors.concat(27shortObjectsVisitors,28conciseMethodVisitors29);30});3132function transform(code) {33return transformFn(visitors, code).code;34}3536it('handles spread with concise methods and short notation', function() {37var code = 'var xyz = { ...x, y() { return 42; }, z }';38var objectAssignMock = jest.genMockFunction();39Object.assign = objectAssignMock;40eval(transform(code));4142var assignCalls = objectAssignMock.mock.calls;43expect(assignCalls.length).toBe(1);44expect(assignCalls[0].length).toBe(3);45expect(assignCalls[0][0]).toEqual({});46expect(assignCalls[0][1]).toEqual(x);4748var trailingObject = assignCalls[0][2];49expect(trailingObject.y()).toEqual(42);50expect(trailingObject.z).toEqual(z);51});5253it('does not call assign when there are no spread properties', function() {54var code = 'var xyz = { x, y() { return 42 }, z }';55var objectAssignMock = jest.genMockFunction();56Object.assign = objectAssignMock;57eval(transform(code));58expect(objectAssignMock).not.toBeCalled();59});6061});626364