import { it } from '@jest/globals';
import { newSpecPage } from '@stencil/core/testing';
import { stringifyProps } from './stringifyProps';
/**
 * Check that component has settable ID
 */
const hasTestId = async (component, tagName, props) => {
  it(`has settable data-testid`, async () => {
    let expandedProps = '';
    if (props !== undefined) {
      expandedProps = stringifyProps(props);
    }
    //
    // Render component
    const page = await newSpecPage({
      components: [component],
      html: `<${tagName} ${expandedProps} data-testid="unique-id"></${tagName}>`,
    });
    // Get first element
    const element = page.root;
    const attrValues = element.getAttribute('data-testid');
    expect(element).toHaveAttribute('data-testid'); // Check of value with this did not fail if needed
    expect(attrValues).toBe('unique-id');
  });
};
export default hasTestId;
