avajs / eslint-plugin-ava

ESLint rules for AVA
https://avajs.dev
MIT License
229 stars 49 forks source link

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

Open schmod opened 2 years ago

schmod commented 2 years ago
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();
    });
  });
novemberborn commented 2 years ago

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?

schmod commented 2 years ago

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