The Wayback Machine - https://web.archive.org/web/20210125073544/https://github.com/infernojs/inferno/issues/1363
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

why does the inferno-test-utils require the DOM as the second param? #1363

Closed
aprilmintacpineda opened this issue Jun 30, 2018 · 9 comments
Closed

Comments

@aprilmintacpineda
Copy link

@aprilmintacpineda aprilmintacpineda commented Jun 30, 2018

I think it should be removed since it should automatically know to use inferno-dom (which I tried using but I got an error saying it's deprecated) or whatever.

The docs should really be improved.

@Havunen
Copy link
Member

@Havunen Havunen commented Jul 1, 2018

inferno-dom is legacy and will not work. What method you are talking about here? This documentation https://github.com/infernojs/inferno/tree/master/packages/inferno-test-utils or something else?

@aprilmintacpineda
Copy link
Author

@aprilmintacpineda aprilmintacpineda commented Jul 1, 2018

This function requires a DOM.

So where do I get the DOM? why need the DOM? isn't there an option similar to react-test-renderer that does not require the dom as the parameter. You just give it the component and that's it.

@Havunen
Copy link
Member

@Havunen Havunen commented Jul 1, 2018

@aprilmintacpineda Something like this could work

let container;

beforeEach(() => {
    container = document.createElement('div');
    document.body.appendChild(container); // This is needed for synthetic events fe. clicks
});

afterEach(() => {
   render(null, container); // Tear down, to remove events
   document.body.removeChild(container);
});

describe('', () => {
    it('your test', () => {});
});
@sprlwrksAprilmintacpineda

That's going to require mocking the document.body because running tests is on nodejs environment, document.body does not exists there, right?

@sprlwrksAprilmintacpineda

Basically, what I want to do, is I want to be able to do this with inferno-js

https://github.com/aprilmintacpineda/react-context-api-store/blob/master/__tests__/provider.spec.js

Notice that I did not have to mock anything about the DOM. All I needed to do was call renderer.create(<div>I'm a component</div>) and that's it.

@Havunen
Copy link
Member

@Havunen Havunen commented Jul 5, 2018

Inferno is made DOM in mind. There are no plans to build Inferno native. You need jsDOM If you want to run tests in Node

@Havunen
Copy link
Member

@Havunen Havunen commented Sep 18, 2018

Somebody could build custom renderer that fakes out native DOM APIs providing some simple objects

@IgnusG
Copy link

@IgnusG IgnusG commented Oct 16, 2018

@sprlwrksAprilmintacpineda If you want simple out of the box testing for your components you could use enzyme along with enzyme-adapter-inferno.

Support for V6 will be coming shortly hopefully

@Havunen
Copy link
Member

@Havunen Havunen commented Jul 17, 2019

The second parameter of render is used to target rendering. It could be Html Node, element, or similar fake JS object (jsDOM?)

@Havunen Havunen closed this Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants