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

Component unit test this.render() call doesn't support passing in content #182

Closed
stevesims opened this issue Aug 11, 2015 · 7 comments
Closed

Comments

@stevesims
Copy link

I'm currently writing a component that on didInsertElement looks at it's content and updates some internal state. The template for the component has a {{yield}} for this content.

When I came to write a unit test for this behaviour in the vein of an integration test I wrote a call to this.render passing in some markup, expecting it to be rendered in the component's {{yield}}. My test then checked the internal state of the component to see if things had worked correctly, but sadly the test failed. My processing call had been made, but it found no content to work with.

The reason for this appears to be that this.render in unit tests works differently from their integration test counterparts, and content passed in gets ignored and thrown away.

I have worked around this by explicitly setting component.element.innerHTML and then calling my processing routine, however this feels like a bodge. It's not providing a proper test for how the component is intended to be used.

Can we have this.render work more consistently please?

@turboMaCk
Copy link

👍
@stevesims Did you find some better solution for this?

@rwjblue
Copy link
Member

rwjblue commented Sep 9, 2015

This issue seems to be down the wrong track. The template passed to this.render is used to render the components.

Demo: http://jsbin.com/muteqe/edit?html,js,output

Closing this for now, as I believe that the demo above shows this works properly. I am happy to reopen if I am incorrect (please tweak the JSBin to demonstrate the issue).

@rwjblue rwjblue closed this as completed Sep 9, 2015
@turboMaCk
Copy link

I would like to use integration test by I can not figure out how can I test async side effect within it. This is why I decided to use unit test for that test. I'll try even little bit more, but I spend whole day on it already. If I have some idea how can I simplify whole problem and simulate it in JSBin I will post link later. Actual component is way too complex.

@rwjblue
Copy link
Member

rwjblue commented Sep 10, 2015

What kind of async? It should be possible to do, if you can describe what kind of thing you are doing in your component maybe I can help with a way forward.

As it stands, this.render in unit tests does not take arguments (as you discovered/reported), and I generally haven't had situations where I needed a component unit test with this.render where an integration test wasn't better in the end.

@stevesims
Copy link
Author

This tweak to the JSBin demonstrates the issue:
http://jsbin.com/vuyifocupu/edit?html,js,output

I've got integration tests too, but I wanted to have unit tests that check out the internal API of my component to make sure they work correctly. My component needs to process content passed through to it to set up its state.

@rwjblue
Copy link
Member

rwjblue commented Sep 10, 2015

When using a component unit test, you cannot supply arguments to this.render (which is the issue you are reporting I think). This is very specifically why component integration tests were created in the first place! We need a way to actually interact with the component as it is actually used in the app (which means to create it from a template snippet).

@turboMaCk
Copy link

For example. How can I fix this integration test if there is no andThen? http://jsbin.com/siriwuzeca/edit?js,output

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

3 participants