ionic-team / stencil

A toolchain for building scalable, enterprise-ready component systems on top of TypeScript and Web Component standards. Stencil components can be distributed natively to React, Angular, Vue, and traditional web developers from a single, framework-agnostic codebase.
https://stenciljs.com
Other
12.59k stars 789 forks source link

bug: relative link in href gets modified in tests to absolute links #3214

Closed raspyweather closed 2 years ago

raspyweather commented 2 years ago

Prerequisites

Stencil Version

2.7.0

Current Behavior

Unit Tests for Components cannot properly test href's due to relative url's being manipulated by the framework.

Expected Behavior

relative href values staying unchanged or documentation to exist

Steps to Reproduce

Example component

render() {
    return (
      <Host>
        <a href={this.link}>Test</a>
        <slot></slot>
      </Host>
    );

Related test case:

  // OUTPUT:
  // Expected: "/"
  // Received: "http://testing.stenciljs.com/"
  it('expect link not to be changed', async () => {
    const page = await newSpecPage({
      components: [LinkTest],
      html: `<link-test link="/"></link-test>`,
    });
    const element = page.root.querySelector<HTMLAnchorElement>("a");
    expect(element.href).toBe("/");
  });
});

Code Reproduction URL

https://github.com/raspyweather/stencil-issues/blob/master/src/components/link-test/test/link-test.spec.tsx

Additional Information

No response

tricki commented 2 years ago

The href property of anchor tags is always the resolved absolute value. You can access the attribute with element.getAttribute('href').

Does that fix your issue?

raspyweather commented 2 years ago

Yes, thank you.