TestHarness helper function fails for MatButtonHarness

20 Views Asked by At

Given this helper function:

async function findHarnessByTestID(
    typeQualifier: (options?: InputHarnessFilters | undefined) => HarnessPredicate<any>, 
    testId: string) {
       return loader.getHarness(typeQualifier({ selector: `[data-test-id=${testId}]` }));
}

This test works just fine:

it('shows the icon', async () => {
   const icon = (await findHarnessByTestID(MatIconHarness.with, 'icon-test-id')) as MatIconHarness;
   expect(await icon.getName()).to.equal('alarm');
});

But this test does not:

it('shows the row menu items', async () => {
  const menuButtonHarness = (await findHarnessByTestID(MatButtonHarness.with, 'button-test-id')) as MatButtonHarness;
  expect(true).to.be.true;
}

I recognize the helper function isn't particularly useful, but I would like to understand what's breaking here. Can anyone see why this breaks for MatButtonHarness but not for MatIconHarness?

Error output:

ERROR: 'Unhandled Promise rejection:', 'Cannot read properties of undefined (reading 'hostSelector')', '; Zone:', 'ProxyZone', '; Task:', 'mocha.forceTask', '; Value:', TypeError: Cannot read properties of undefined (reading 'hostSelector') TypeError: Cannot read properties of undefined (reading 'hostSelector') at HarnessPredicate.getSelector (http://localhost:4201/karma_webpack/webpack:/node_modules/@angular/cdk/fesm2022/testing.mjs:337:38) at map (http://localhost:4201/karma_webpack/webpack:/node_modules/@angular/cdk/fesm2022/testing.mjs:512:123) at Array.map () at http://localhost:4201/karma_webpack/webpack:/node_modules/@angular/cdk/fesm2022/testing.mjs:512:96 at Generator.next () at asyncGeneratorStep (http://localhost:4201/karma_webpack/webpack:/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:3:1) at _next (http://localhost:4201/karma_webpack/webpack:/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:22:1) at executor (http://localhost:4201/karma_webpack/webpack:/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:27:1) at ZoneAwarePromise (http://localhost:4201/karma_webpack/webpack:/node_modules/zone.js/fesm2015/zone.js:1411:21) at http://localhost:4201/karma_webpack/webpack:/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:19:1, 'TypeError: Cannot read properties of undefined (reading 'hostSelector') at HarnessPredicate.getSelector (http://localhost:4201/karma_webpack/webpack:/node_modules/@angular/cdk/fesm2022/testing.mjs:337:38) at map (http://localhost:4201/karma_webpack/webpack:/node_modules/@angular/cdk/fesm2022/testing.mjs:512:123) at Array.map () at http://localhost:4201/karma_webpack/webpack:/node_modules/@angular/cdk/fesm2022/testing.mjs:512:96 at Generator.next () at asyncGeneratorStep (http://localhost:4201/karma_webpack/webpack:/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:3:1) at _next (http://localhost:4201/karma_webpack/webpack:/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:22:1) at executor (http://localhost:4201/karma_webpack/webpack:/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:27:1) at ZoneAwarePromise (http://localhost:4201/karma_webpack/webpack:/node_modules/zone.js/fesm2015/zone.js:1411:21) at http://localhost:4201/karma_webpack/webpack:/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:19:1'

0

There are 0 best solutions below