Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81153 views
1
/**
2
* @emails [email protected] [email protected]
3
*/
4
5
/*jshint evil:true*/
6
7
require('mock-modules').autoMockOff();
8
9
describe('es6-es7-object-integration-test', function() {
10
var transformFn;
11
12
var visitors;
13
14
// These are placeholder variables in scope that we can use to assert that a
15
// specific variable reference was passed, rather than an object clone of it.
16
var x = 123456;
17
var z = 345678;
18
19
beforeEach(function() {
20
require('mock-modules').dumpCache();
21
transformFn = require('../../src/jstransform').transform;
22
23
var conciseMethodVisitors = require('../es6-object-concise-method-visitors').visitorList;
24
var shortObjectsVisitors = require('../es6-object-short-notation-visitors').visitorList;
25
var spreadPropertyVisitors = require('../es7-spread-property-visitors').visitorList;
26
27
visitors = spreadPropertyVisitors.concat(
28
shortObjectsVisitors,
29
conciseMethodVisitors
30
);
31
});
32
33
function transform(code) {
34
return transformFn(visitors, code).code;
35
}
36
37
function expectTransform(code, result) {
38
expect(transform(code)).toEqual(result);
39
}
40
41
it('handles spread with concise methods and short notation', function() {
42
var code = 'var xyz = { ...x, y() { return 42; }, z }';
43
var objectAssignMock = jest.genMockFunction();
44
Object.assign = objectAssignMock;
45
eval(transform(code));
46
47
var assignCalls = objectAssignMock.mock.calls;
48
expect(assignCalls.length).toBe(1);
49
expect(assignCalls[0].length).toBe(3);
50
expect(assignCalls[0][0]).toEqual({});
51
expect(assignCalls[0][1]).toEqual(x);
52
53
var trailingObject = assignCalls[0][2];
54
expect(trailingObject.y()).toEqual(42);
55
expect(trailingObject.z).toEqual(z);
56
});
57
58
it('does not call assign when there are no spread properties', function() {
59
var code = 'var xyz = { x, y() { return 42 }, z }';
60
var objectAssignMock = jest.genMockFunction();
61
Object.assign = objectAssignMock;
62
eval(transform(code));
63
expect(objectAssignMock).not.toBeCalled();
64
});
65
66
});
67
68