Skip to content

Commit

Permalink
fix: adjust code to cover branches
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Apr 30, 2022
1 parent e76e724 commit 3601ceb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/rules/__tests__/utils.test.ts
Expand Up @@ -666,6 +666,14 @@ describe('reference checking', () => {
`,
parserOptions: { sourceType: 'script' },
},
{
code: dedent`
const { [() => {}]: it } = require('@jest/globals');
it('is not a jest function', () => {});
`,
parserOptions: { sourceType: 'script' },
},
],
invalid: [
{
Expand Down
12 changes: 5 additions & 7 deletions src/rules/utils.ts
Expand Up @@ -829,19 +829,14 @@ const describeVariableDefAsImport = (
return null;
}

// currently we only support access via destructuring
if (def.node.id.type !== AST_NODE_TYPES.ObjectPattern) {
return null;
}

const sourceNode = findImportSourceNode(def.node.init);

if (!sourceNode || !isStringNode(sourceNode)) {
return null;
}

if (def.name.parent?.type !== AST_NODE_TYPES.Property) {
throw new Error('oh noes!');
return null;
}

if (!isSupportedAccessor(def.name.parent.key)) {
Expand Down Expand Up @@ -890,8 +885,11 @@ const collectReferences = (scope: TSESLint.Scope.Scope) => {
continue;
}

/* istanbul ignore if */
if (ref.defs.length > 1) {
throw new Error('please report this');
throw new Error(
`Reference unexpected had more than one definition - please file a github issue at https://github.com/jest-community/eslint-plugin-jest`,
);
}

const [def] = ref.defs;
Expand Down

0 comments on commit 3601ceb

Please sign in to comment.