简体   繁体   中英

How to unit test Capacitor project?

I have some JavaScript unit tests that I need to run. We use a combination of mocha and chai for the tests. We are looking into possibly switching to Capacitor as a tool to convert web apps to mobile and electron projects. In order to get Capacitor working in our unit tests we have to run the tests using jsdom as Capacitor makes use of the window object. Now the unit tests are run through jsdom these parts of Capacitor are happy and our tests pass.

However we have one module that will require the use of Capacitor's Filesystem API. Filesystem has no web implementation so these tests now fail as we are using jsdom. The log states Filesystem does not have web implementation. . Is there any way I can get a combination of having window available in our unit tests while also allowing the use of Filesystem ?

I was able to fix this. I used jsdom from the terminal and it didn't work. However using the JavaScript API I was able to get that test to pass.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM