react-ionize icon indicating copy to clipboard operation
react-ionize copied to clipboard

Testing of elements

Open Vlemert opened this issue 8 years ago • 4 comments

Thought I'd get a topic started on the tests.

I ran into some issues when trying to write a test for acceptFirstMouse, which seem to be related to the fact that the electron mock creates instances of _BrowserWindow on its own (like here). This works as long as you don't really care about how the constructor was called, but when checking for options that are passed to the constructor things get a bit tricky.

An idea I had was that instead allowing the electron mock to create instances whenever it wants, it could allow tests to register a callback that is called whenever the BrowserWindow constructor mock is called. This way, tests could register a callback to stub whatever they need, and all instances are created 'on demand', instead of whenever the electron mock is loaded or getWindow is called.

Let me know what you think. If you want, I could get something going and submit a PR.

Vlemert avatar Apr 19 '17 19:04 Vlemert

I'd definitely be interested to see a better strategy for testing. For what it's worth, I'm totally fine with ripping out the existing mocks as long as there's an equivalently succinct way to build mocks in the spec files themselves.

Do you suppose you could put together a proof-of-concept? I'm trying to get some features done this weekend, so I'll be around to check it out then.

mhink avatar Apr 21 '17 02:04 mhink

Yeah I'll try to throw something together Saturday or Sunday that's compatible with the current requirements. I guess you'll see a pull request when I've got something.

Vlemert avatar Apr 21 '17 11:04 Vlemert

Mocking electron apis as you currently are probably makes tests run more reliably and faster, but have you considered https://github.com/electron/spectron?

bmathews avatar Apr 21 '17 14:04 bmathews

Hadn't considered that yet @bmathews. For now I've made some small changes to the mocks that give us a bit more options, but spectron may very well be worth investigating.

Vlemert avatar Apr 22 '17 10:04 Vlemert