Skip to content

Conversation

@G-Rath
Copy link
Collaborator

@G-Rath G-Rath commented Jul 20, 2019

No description provided.

},
defaultOptions: [
{ fn: 'test', withinDescribe: 'it' } as {
fn?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use the enum instead of string?

const nodeName = getNodeName(node.callee);

if (!nodeName) {
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new, but seeing as tests pass I guess it doesn't matter.

Copy link
Collaborator Author

@G-Rath G-Rath Jul 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's required by typescript - getNodeName could always return null, but not always checked:

export const getNodeName = node => {
  function joinNames(a, b) {
    return a && b ? `${a}.${b}` : null;
  }

  switch (node && node.type) {
    case 'Identifier':
      return node.name;
    case 'MemberExpression':
      return joinNames(getNodeName(node.object), getNodeName(node.property));
  }

  return null;
};

Ah, the joys of complex ASTs 😂

Copy link
Collaborator Author

@G-Rath G-Rath Jul 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seeing as tests pass I guess it doesn't matter.

I believe this is b/c of the isDescribe - the conditions for which getNodeName would return null are mutually exclusive w/ isDescribe, which is why this has never been a problem.

I mean, that branch must be being hit b/c coverage isn't complaining, so it can happen.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so it's written down somewhere, this is the code that can be used to make getNodeName to return null:

[1,2,3].forEach(() => { test("foo") })

It's b/c [1,2,3] is an ArrayExpression, which causes getNodeName to bail out.

I needed to know how to do this to implement a test for another rule to get coverage other the line :)

},
defaultOptions: [
{ fn: 'test', withinDescribe: 'it' } as {
fn?: 'it' | 'test';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need as const on the schema?

Copy link
Member

@SimenB SimenB Jul 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might not need the type info here then. Maybe not though, not sure how enum in schema works

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not as far as I'm aware - the schema is json schema, so it's not actually used by TS (it'd be cool if it was, but it's far too complex)

@SimenB SimenB merged commit 3fd4a15 into jest-community:reapply-ts Jul 20, 2019
@G-Rath G-Rath deleted the ts-migration/consistent-test-it branch July 20, 2019 21:23
SimenB pushed a commit that referenced this pull request Jul 22, 2019
SimenB pushed a commit that referenced this pull request Jul 22, 2019
@SimenB SimenB mentioned this pull request Jul 22, 2019
35 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants