eslint-plugin-ava icon indicating copy to clipboard operation
eslint-plugin-ava copied to clipboard

cannot destructure property 'type' or 'node' as it is undefined

Open schmod opened this issue 3 years ago • 2 comments
trafficstars

ESLint: 8.8.0

TypeError: Cannot destructure property 'type' of 'node' as it is undefined.
Occurred while linting /Users/schmod/myCode/myTest-unit.ts:118
Rule: "ava/assertion-arguments"
    at isString (/Users/schmod/myCode/node_modules/eslint-plugin-ava/rules/assertion-arguments.js:206:9)
    at /Users/schmod/myCode/node_modules/eslint-plugin-ava/rules/assertion-arguments.js:294:10
    at /Users/schmod/myCode/node_modules/enhance-visitors/index.js:25:12
    at /Users/schmod/myCode/node_modules/enhance-visitors/index.js:15:7
    at ruleErrorHandler (/Users/schmod/myCode/node_modules/eslint/lib/linter/linter.js:1107:28)
    at /Users/schmod/myCode/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/schmod/myCode/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/schmod/myCode/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (/Users/schmod/myCode/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
error Command failed with exit code 2.

Cleaned-up version of the relevant test:

test('a test', async (t) => {
    const tests: Test[] = []
      [
        'returns null when blah blah blah',
        'val1',
        'val2',
        () => makeSomeMocks()
      ],
    ];
  
    await pEachSeries(tests, async ([testName, val1, val2, mocks]) => {
      const testSubject = await getTestSubject();
      t.is(testSubject.aFunction(val1), val2, testName);
      if (mocks != null) mocks.reset();
    });
  });

schmod avatar Feb 02 '22 01:02 schmod

Is it expecting testName to be a string, and blowing up because it's a variable? What happens if you turn it into a string?

novemberborn avatar Feb 06 '22 16:02 novemberborn

Sorry for the very late update, but this indeed works if I wrap testName in a template literal (ie. ${testName})

schmod avatar Sep 14 '22 21:09 schmod