-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Support template depency stubbing #88
Support template depency stubbing #88
Conversation
This builds on #87 and may need to be rebased when that gets merged. |
This is starting to get somewhat urgent for us: we've got over 400 tests using aurelia-testing by now, and every so often adding a new test for a composed component will start breaking existing tests. We need better isolation. If there's anything I can do to help speed up adoption of this change, let me know. |
@RomkeVdMeulen Can you add me to collaborator of your repo? I wanna add some more tests to it before we progress. Or you can also do it, to make it closer to your real world app. Those tests should be related to compose scenario, html only element, absolute url resolution |
@bigopon That sounds good. Could you make a start so I can get an idea for what you have in mind? I'll add any scenarios I can think of. |
<template>
<require from="./a.html"></require>
</template> In test: StageComponent
.inView('<compose view="path/to/html-only-above.html"></compose>')
.inView('<compose view-model="path/to/some-view-model-with-require"></compose>')
.inView('<compose view-model="path/to/some-view-model-with-absolute-url.html"></compose>') There could be more scenarios, but those are probably the basic, related to |
Wouldn't a separate PR be better then? I'm hoping this feature can be rolled out soon so I can start properly isolating our own tests. |
then let's see what @EisenbergEffect 'd say |
We don't need to add all the tests now. We can do a follow-up PR. But, did we get the one initial test working or is that broken? |
it('prevents the matching dependency from being loaded even if a template <require>s it', async () => {
stubTemplateDependency('dist/test/test/resources/my-component');
const component = await StageComponent
.withResources('dist/test/test/resources/my-parent-component')
.inView('<my-parent-component></my-parent-component>');
await component.create(bootstrap);
let subComponent = component.element.firstElementChild as HTMLElement;
expect(subComponent.tagName.toLowerCase()).toEqual('my-component');
expect(subComponent.innerHTML.trim()).toEqual('');
await component.dispose();
resetStubbedTemplateDependencies();
await component.create(bootstrap);
subComponent = component.element.firstElementChild as HTMLElement;
expect(subComponent.innerHTML.trim()).not.toEqual('');
await component.dispose();
}); Still broken. I wanted the test to show that if you reset the stubbed dependencies and then load the same component again, the subcomponent will be loaded. But when the parent component is loaded again, the template registry entry isn't being rebuilt. My guess is that the entry with stubbed dependencies remains cached somewhere, but I don't know enough about templating / loading internals to know where to look. |
@bigopon Would you be able to help @RomkeVdMeulen track down this issue. If we can get that fixed, then we can merge this and get it out. After that we can follow up with additional tests for more scenarios. This one seems pretty critical for real use though. |
@RomkeVdMeulen Sorry I thought you already got that test working. I'll have a look |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good first step towards shallow rendering like used with Enzyme. I'd just wonder what happens If you stub twice. Might throw an error that the template is already stubbed. This may happen when using a beforeEach plus another nested one.
Superseded by #89 |
See #20. Replaces aurelia/loader#27
I wasn't able to get the test to work: the template registry entry isn't being rebuilt during the second run. I'm guessing the entry is being cached somewhere. Some help with this would be much appreciated.