Skip to content
This repository has been archived by the owner on Jul 12, 2019. It is now read-only.

Add optional parameter to createAppTester to customize storeKey #147

Merged
merged 3 commits into from
Apr 1, 2019

Conversation

michellechu77
Copy link
Contributor

  • Updated index.d.ts

@michellechu77 michellechu77 requested a review from xavdid March 28, 2019 21:43
@michellechu77
Copy link
Contributor Author

@xavdid, wasn't too familiar with the index.dt.s file format, but took a guess at it.

@michellechu77 michellechu77 self-assigned this Mar 28, 2019
Copy link
Contributor

@xavdid xavdid left a 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.

index.d.ts Outdated Show resolved Hide resolved
@@ -36,7 +36,7 @@ const promisifyHandler = handler => {
};

// A shorthand compatible wrapper for testing.
const createAppTester = appRaw => {
const createAppTester = (appRaw, storeKey = null) => {
Copy link
Contributor

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?

Copy link
Contributor

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. 😁

@@ -46,14 +46,15 @@ const createAppTester = appRaw => {
bundle = bundle || {};

const method = resolveMethodPath(appRaw, methodOrFunc);
let myStoreKey = storeKey ? `testKey-${storeKey}` : `testKey-${method}-${randomSeed}`
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@michellechu77 michellechu77 merged commit 5a5a042 into master Apr 1, 2019
@michellechu77 michellechu77 deleted the add_parameter_to_app_tester branch April 1, 2019 14:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants