jeudi 4 octobre 2018

How to test UI of HTML file in headless browser using Mocha.js

I have a bunch of unit tests:

/tests/modules/unit-test-1.js
/tests/modules/unit-test-2.js
/tests/modules/unit-test-3.js
...
..

that I run by doing:

mocha ./tests/modules/*.js

I also have a my-ui.html file and I want to run a UI test on that file. For this, I want to add a /tests/modules/ui-test-1.js to the above list and what I want this file to do is:

  1. load my-ui.html in a headless chrome
  2. use jQuery to look for some elements on the loaded file
  3. run some Mocha assertions on the above jQuery findings

I want to still be able to run mocha ./tests/modules/*.js and have all my tests run one by one, regardless of whether some of them will be unit tests or UI tests.

There are so many tools but no clear guidelines on how to do the above using Mocha. Any suggestions will be most welcome :)

I must clarify that I do not want to run my test results in the browser using some Mocha UI (I know there are guidelines about that..) - What I want is to load some local file in a headless browser and run Mocha assertions using jQuery on the DOM of that loaded HTML. The results of all my tests will keep appearing in the terminal as is currently the case.

Aucun commentaire:

Enregistrer un commentaire