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

Correct way to test client code #2

Open
james-m-henderson opened this issue Oct 13, 2016 · 3 comments
Open

Correct way to test client code #2

james-m-henderson opened this issue Oct 13, 2016 · 3 comments

Comments

@james-m-henderson
Copy link

What is the "right" way to add client code tests?

I tried the obvious:

require(TEST_HELPER) // <--- This must be at the top of every test file

var request = require('supertest-as-promised')
var app = require(__client + '/app.js')
...

But it fails since the window is not defined. Simply setting window = global doesn't work either since then "document" can't be found.

I guess the next step would be to use m.deps() and set mock objects for the window and document, but I'm wondering if I'm missing anything, or if it would make sense to integrate this stuff into the boilerplate.

@gilbert
Copy link
Member

gilbert commented Oct 15, 2016

If you're testing mithril code, I recommend using mithril-query to test your components in isolation. If components use window directly, try refactoring to receive as component args instead.

@james-m-henderson
Copy link
Author

Testing the components is easy enough if they aren't using the globals (using mithril-query for example). I was trying to test the example application itself app.js, which does use window directly to store application state. Do you think it makes sense for the boilerplate to include a test for app.js?

@gilbert
Copy link
Member

gilbert commented Oct 16, 2016

I normally don't test the routing layer, and instead try to keep it as thin as possible. For window.App, you can set those in your tests as global.App = { ... }, and use App without window/global in your components.

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