jest-mock
Advanced tools
Comparing version 14.3.0-alpha.d13c163e to 14.3.1-alpha.410cb91a
@@ -24,53 +24,56 @@ /** | ||
const RESERVED_KEYWORDS = [ | ||
'do', | ||
'if', | ||
'in', | ||
'for', | ||
'let', | ||
'new', | ||
'try', | ||
'var', | ||
'case', | ||
'else', | ||
'enum', | ||
'eval', | ||
'null', | ||
'this', | ||
'true', | ||
'void', | ||
'with', | ||
'await', | ||
'break', | ||
'catch', | ||
'class', | ||
'const', | ||
'false', | ||
'super', | ||
'throw', | ||
'while', | ||
'yield', | ||
'delete', | ||
'export', | ||
'import', | ||
'public', | ||
'return', | ||
'static', | ||
'switch', | ||
'typeof', | ||
'default', | ||
'extends', | ||
'finally', | ||
'package', | ||
'private', | ||
'continue', | ||
'debugger', | ||
'function', | ||
'arguments', | ||
'interface', | ||
'protected', | ||
'implements', | ||
'instanceof']; | ||
const MOCK_CONSTRUCTOR_NAME = 'mockConstructor'; | ||
// $FlowFixMe | ||
const RESERVED_KEYWORDS = Object.assign(Object.create(null), { | ||
do: true, | ||
if: true, | ||
in: true, | ||
for: true, | ||
let: true, | ||
new: true, | ||
try: true, | ||
var: true, | ||
case: true, | ||
else: true, | ||
enum: true, | ||
eval: true, | ||
null: true, | ||
this: true, | ||
true: true, | ||
void: true, | ||
with: true, | ||
await: true, | ||
break: true, | ||
catch: true, | ||
class: true, | ||
const: true, | ||
false: true, | ||
super: true, | ||
throw: true, | ||
while: true, | ||
yield: true, | ||
delete: true, | ||
export: true, | ||
import: true, | ||
public: true, | ||
return: true, | ||
static: true, | ||
switch: true, | ||
typeof: true, | ||
default: true, | ||
extends: true, | ||
finally: true, | ||
package: true, | ||
private: true, | ||
continue: true, | ||
debugger: true, | ||
function: true, | ||
arguments: true, | ||
interface: true, | ||
protected: true, | ||
implements: true, | ||
instanceof: true }); | ||
function isA(typeName, value) { | ||
@@ -157,3 +160,4 @@ return Object.prototype.toString.apply(value) === '[object ' + typeName + ']'; | ||
let name = metadata.name; | ||
if (!name) { | ||
// Special case functions named `mockConstructor` to guard for infinite loops. | ||
if (!name || name === MOCK_CONSTRUCTOR_NAME) { | ||
return mockConstructor; | ||
@@ -176,11 +180,15 @@ } | ||
// as name. | ||
if (RESERVED_KEYWORDS.indexOf(name) !== -1) { | ||
if (RESERVED_KEYWORDS[name]) { | ||
name = '$' + name; | ||
} | ||
if (/\s/.test(name)) { | ||
name = name.replace(/\s/g, '$'); | ||
} | ||
/* eslint-disable no-new-func */ | ||
return new Function( | ||
'mockConstructor', | ||
MOCK_CONSTRUCTOR_NAME, | ||
'return function ' + name + '() {' + | ||
'return mockConstructor.apply(this,arguments);' + | ||
'return ' + MOCK_CONSTRUCTOR_NAME + '.apply(this,arguments);' + | ||
'}' + bindCall)( | ||
@@ -187,0 +195,0 @@ mockConstructor); |
{ | ||
"name": "jest-mock", | ||
"version": "14.3.0-alpha.d13c163e", | ||
"version": "14.3.1-alpha.410cb91a", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
15717
417