Skip to content

Commit a0dbff1

Browse files
committed
Change proposed solution
The proposed solution didn't work, because the `arguments.length` was always 2 since it was an internal private method. Since this is about to be rewritten anyway I just tacked on a stupid third arg that measures arg length on the public function. I also removed the extra error message since the original message is actually probably clearer. I highly doubt anyone is intentionally relying on this, so a compat notice isn't very necessary IMO
1 parent e57296b commit a0dbff1

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

regression/src/object-test.coffee

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ describe 'td.object', ->
3434
When -> @testDouble = td.object(Object.create(respond: -> 'no'))
3535
Then -> td.explain(@testDouble.respond).isTestDouble == true
3636

37+
describe 'passing undefined raises error / compatibility note', ->
38+
When -> try td.object(undefined) catch error then @error = error
39+
Then -> /pass it a plain object/.test(@error.message)
40+
3741
if global.Proxy?
38-
describe 'creating a proxy object (ES2015; only supported in FF + Edge atm)', ->
42+
describe 'creating a ES Proxy object', ->
3943
Given -> @testDouble = td.object('thing')
4044
Given -> @testDouble.magic('sauce')
4145
When -> td.when(@testDouble.whateverYouWant()).thenReturn('YESS')

src/object.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@ import imitate from './imitate'
55

66
const DEFAULT_OPTIONS = {excludeMethods: ['then']}
77

8-
export default (nameOrType, config) =>
9-
_.tap(fakeObject(nameOrType, config), (obj) => {
8+
export default function object (nameOrType, config) {
9+
return _.tap(fakeObject(nameOrType, config, arguments.length), (obj) => {
1010
addToStringToDouble(obj, nameOrType)
1111
})
12+
}
1213

13-
var fakeObject = (nameOrType, config) => {
14+
var fakeObject = function (nameOrType, config, argCount) {
1415
if (_.isArray(nameOrType)) {
1516
return createTestDoublesForFunctionNames(nameOrType)
1617
} else if (_.isObjectLike(nameOrType)) {
1718
return imitate(nameOrType)
18-
} else if (_.isString(nameOrType) || arguments.length === 0) {
19+
} else if (_.isString(nameOrType) || argCount === 0) {
1920
return createTestDoubleViaProxy(nameOrType, withDefaults(config))
20-
} else if (nameOrType === undefined) {
21-
ensureUndifinedVariableNotPassed()
2221
} else if (_.isFunction(nameOrType)) {
2322
ensureFunctionIsNotPassed()
2423
} else {
@@ -58,9 +57,6 @@ Did you mean \`td.object(['${name}'])\`?\
5857
}
5958
}
6059

61-
var ensureUndifinedVariableNotPassed = () =>
62-
log.error('td.object', `undefined variable was passed to \`td.object\` (as of [email protected]). Please use \`td.object()\` or \`td.object('someString')\` to create a test doulbe via proxy.`)
63-
6460
var ensureFunctionIsNotPassed = () =>
6561
log.error('td.object', `Functions are not valid arguments to \`td.object\` (as of [email protected]). Please use \`td.function()\` or \`td.constructor()\` instead for creating fake functions.`)
6662

0 commit comments

Comments
 (0)