Skip to content

Commit

Permalink
Update module mocker code.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpojer committed Oct 2, 2015
1 parent 4ed0221 commit c72c5eb
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 338 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"devel": true,
"dojo": false,
"eqeqeq": true,
"eqnull": false,
"eqnull": true,
"esnext": true,
"evil": false,
"expr": true,
Expand Down
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
language: node_js
node_js:
- "iojs-v2"
- "iojs-v3"
- "4"
sudo: false
14 changes: 7 additions & 7 deletions src/HasteModuleLoader/HasteModuleLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ Loader.prototype._execModule = function(moduleObj) {
moduleObj.require = this.constructBoundRequire(modulePath);

var moduleLocalBindings = {
'module': moduleObj,
'exports': moduleObj.exports,
'require': moduleObj.require,
'__dirname': path.dirname(modulePath),
'__filename': modulePath,
'global': this._environment.global,
'jest': this._builtInModules['jest-runtime'](modulePath).exports
module: moduleObj,
exports: moduleObj.exports,
require: moduleObj.require,
__dirname: path.dirname(modulePath),
__filename: modulePath,
global: this._environment.global,
jest: this._builtInModules['jest-runtime'](modulePath).exports
};

var onlyCollectFrom = this._config.collectCoverageOnlyFrom;
Expand Down
68 changes: 24 additions & 44 deletions src/lib/__tests__/moduleMocker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
*/
'use strict';

// This was generated with https://babeljs.io/repl/
/* jshint ignore:start */
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
/* jshint ignore:end */
/* global _classCallCheck, _createClass */

jest.autoMockOff();

describe('moduleMocker', function() {
Expand All @@ -36,7 +29,7 @@ describe('moduleMocker', function() {
it('forwards the function name property', function() {
function foo(){}
var fooMock = moduleMocker.generateFromMetadata(
moduleMocker.getMetadata(foo)
moduleMocker.getMetadata(foo)
);
expect(fooMock.name).toBe('foo');
});
Expand Down Expand Up @@ -80,42 +73,29 @@ describe('moduleMocker', function() {
expect(fooMock.nonEnumGetter).toBeUndefined();
});

it('mocks ES6 non-enumerable methods', function() {
// ES6: class ClassFoo { foo() { } }
// Converted with https://babeljs.io/repl/
var ClassFoo = (function () {
function ClassFoo() {
_classCallCheck(this, ClassFoo);
}

_createClass(ClassFoo, [{
key: 'foo',
value: function foo() {}
}, {
key: 'toString',
value: function toString() {
return 'Foo';
}
}]);

return ClassFoo;
})();
var ClassFooMock = moduleMocker.generateFromMetadata(
moduleMocker.getMetadata(ClassFoo)
);

var foo = new ClassFooMock();

var instanceFoo = new ClassFoo();
var instanceFooMock = moduleMocker.generateFromMetadata(
moduleMocker.getMetadata(instanceFoo)
);

expect(typeof foo.foo).toBe('function');
expect(typeof instanceFooMock.foo).toBe('function');
expect(instanceFooMock.foo.mock).not.toBeUndefined();

expect(instanceFooMock.toString.mock).not.toBeUndefined();
it('mocks ES2015 non-enumerable methods', function() {
class ClassFoo {
foo() {}
toString() {
return 'Foo';
}
}

var ClassFooMock = moduleMocker.generateFromMetadata(
moduleMocker.getMetadata(ClassFoo)
);
var foo = new ClassFooMock();

var instanceFoo = new ClassFoo();
var instanceFooMock = moduleMocker.generateFromMetadata(
moduleMocker.getMetadata(instanceFoo)
);

expect(typeof foo.foo).toBe('function');
expect(typeof instanceFooMock.foo).toBe('function');
expect(instanceFooMock.foo.mock).not.toBeUndefined();

expect(instanceFooMock.toString.mock).not.toBeUndefined();
});
});
});
Loading

0 comments on commit c72c5eb

Please sign in to comment.