vendredi 29 mai 2015

Testing functionality based on HTML5 DOM-methods

I'm wondering how to test functionality based on HTML5 DOM-methods. Like the new dialog-API for example.

Consider the following function;

function show(dialog)
{
    if(typeof(dialog.showModal) !== "function")
        throw new Error("Update your browser");
    dialog.showModal();
}

I want to make sure that

  1. an error is thrown when the method is not available
  2. dialog.showModal is called if available

I'm currently running karma + jasmine with the firefox and chrome launchers but none of them seems to support the dialog-API.

Can I shim this in some kind of way? Can I create a function on all dialog DOM nodes?

I could do the following

var modal = document.createElement("dialog");
Object.defineProperty(modal, "showModal", {
    value: function()
    {
        console.log("hello world!");
    }
});

however, that isn't carried over to other instances of a dialog.

This is a very simplified example of what I'm trying to achieve.

Aucun commentaire:

Enregistrer un commentaire