acvetkov / sinon-chrome

Testing chrome extensions with Node.js
ISC License
434 stars 46 forks source link

How to test DOM update without displaying the page? #64

Open kaidatavis opened 6 years ago

kaidatavis commented 6 years ago

Hi,

I am using Sinon-Chrome to test a Chrome extension. One of the functions is that user can highlight text on a web page. This is how I think I can test this with Sinon-Chrome:

  1. Send the extension an text selection event (using Sinon-Chrome);
  2. The extension updates the DOM to change the text background;
  3. Check if the background of the selected text is changed, such as marked with <mark>.

I think I can do step 1, but don't know how to do step 2 or 3 if I don't want to open a real URL in browser. How to give the Chrome extension a DOM to update (and then check) without open an actual website?

Ideally such a (virtual?) DOM can be loaded from a pre-saved file, so 1) it will be exactly the same every time, and 2) it makes the test synchronous (open a real URL will be asynchronous).