-
Notifications
You must be signed in to change notification settings - Fork 15
Add optional parameter to createAppTester to customize storeKey #147
Conversation
michellechu77
commented
Mar 28, 2019
- Updated index.d.ts
@xavdid, wasn't too familiar with the index.dt.s file format, but took a guess at it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great job!
I left a couple of minor style comments. Feel free to address as you see fit and then merge when you're ready.
src/tools/create-app-tester.js
Outdated
@@ -36,7 +36,7 @@ const promisifyHandler = handler => { | |||
}; | |||
|
|||
// A shorthand compatible wrapper for testing. | |||
const createAppTester = appRaw => { | |||
const createAppTester = (appRaw, storeKey = null) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is good, but typically it's good to avoid null
. It behaves weirdly with default args.
That said, you don't actually have to set a default here. The verbose version of this function signature is (appRaw, storeKey=undefined)
, but since js doesn't really enforce arguments at all, it's most clearly written as (appRaw, storeKey)
. Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see now that you likely copied the null
from below. Honestly I shouldn't have written it like that in the first place. 😁
src/tools/create-app-tester.js
Outdated
@@ -46,14 +46,15 @@ const createAppTester = appRaw => { | |||
bundle = bundle || {}; | |||
|
|||
const method = resolveMethodPath(appRaw, methodOrFunc); | |||
let myStoreKey = storeKey ? `testKey-${storeKey}` : `testKey-${method}-${randomSeed}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
though it's perfect for quick adhoc use, i'd probably name this variable something else. maybe customStoreKey
.
That said, looking below, I'd probably move the ternary up here and rename that variable. So the whole thing would be
(appRaw, customStoreKey) =>
// ...
const storeKey = shouldPaginate(appRaw, method)
? storeKey
? `testKey-${storeKey}`
: `testKey-${method}-${randomSeed}`
: undefined;
// ...
method,
bundle,
storeKey
};
if you go that route, remember to adjust the index.d.ts
appropriately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea, I like your suggested variable name better.