Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ComponentTester] ref + innerhtml not working #91

Open
michaelw85 opened this issue Jun 21, 2019 · 5 comments
Open

[ComponentTester] ref + innerhtml not working #91

michaelw85 opened this issue Jun 21, 2019 · 5 comments

Comments

@michaelw85
Copy link

I'm submitting a bug report
ref and innerhtml not working when using the component tester.

  • ** Steps to reproduce **
  1. checkout repo: https://github.com/michaelw85/repo-aurelia-test-issue
  2. npm install
  3. au jest

au jest will result in an error for the ref issue.
the innerhtml issue is visible in the jest snapshot.

To verify the icons are actually functioning in a normal app use au run to open the dev-app.

  • Library Version:
    aurelia-testing: 1.0.0

Please tell us about your environment:

  • Operating System:
    Windows 10

  • Node Version:
    v10.15.0

  • NPM Version:
    6.9.0
  • JSPM OR Webpack AND Version
    Plugin setup created with CLI, default TS configuration

  • Language:
    TS

Current behavior:
When using a ref binding it is undefined in a unit test when using the component tester.
TypeError: Cannot read property 'setAttribute' of undefined (setAttribute is performed on the elements being referenced)

innerhtml is not rendered, here's a jest snapshot:

<my-icon-inner
  au-target-id="2"
  class="au-target"
  name="angle-up"
>
  
  <!-- This SVG should have inner html with a use element -->
  <svg
    au-target-id="1"
    class="au-target"
    innerhtml.bind="use"
  />
  

</my-icon-inner>

Expected/desired behavior:
ref should work when using the component tester.
innerhtml binding should render when using component tester.

@bigopon
Copy link
Member

bigopon commented Jun 21, 2019

cli-bundler requirejs web typescript karma vscode scaffold-minimum

With test:

import { bootstrap } from 'aurelia-bootstrapper';
import { ComponentTester, StageComponent, waitForDocumentElement } from 'aurelia-testing';

describe('Icon', () => {
    let component: ComponentTester;

    describe('component', () => {
        beforeEach(() => {
            component = StageComponent.withResources('my-icon').inView('<my-icon name="angle-up"></my-icon>');
        });

        it('should render svg icon with href', async () => {
            await component.create(bootstrap);

            const myIcon = await waitForDocumentElement('my-icon')
            expect(myIcon.innerHTML.trim()).toContain('href="src/assets/stack.svg#angle-up"');
        });

        afterEach(() => {
            try {
                component.dispose()
            } catch {
                console.log('dispose error')
            }
        });
    });
});

It works fine. I think there's something wrong with Jest.

@bigopon
Copy link
Member

bigopon commented Jun 21, 2019

@michaelw85 The above is for your my-icon

@michaelw85
Copy link
Author

@bigopon 😲 thx for the reply I did not consider Jest to cause the issue... 🤔 I wonder what it could be.

@bigopon
Copy link
Member

bigopon commented Jun 21, 2019

@michaelw85 maybe Jest is not the issue, but the combination of Jest and a few other stuff? In anyway, I think for normal looking templates, it will & should work just fine

@michaelw85
Copy link
Author

I might investigate a bit more at a later point in time. First thing that pops in my mind is if it might be related to testEnvironment: 'node',.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants