When writing tests for a Wordpress plugin, should i run them inside wordpress or in a normal browser?
- by Nicola Peluchetti
I have started using BDD for a wordpress plugin i'm working on and i'm rewriting the js codebase to do tests. I've encountered a few problems but i'm going steady now, i was wondering if i had the right approach, because i'm writing test that should pass in a normal browser environment and not inside wordpress.
I choose to do this because i want my plugin to be totally indipendent from the wordpress environment, i'm using requirejs in a way that i don't expose any globals and i'm loading my version of jQuery that doesn't override the one that ships with Wordpress. In this way my plugin would work the same on every wordpress version and my code would not break if they cheange the jQuery version or someone use my plugin on an old wordpress version.
I wonder if this is the right approach or if i should always test inside the environment i'm working in. Since wordpress implies some globals i had to write some function purely for testing purpose, like
"get_ajax_url": function() {
if( typeof window.ajaxurl === "undefined" ) {
return "http://localhost/wordpress/wp-admin/admin-ajax.php";
} else {
return window.ajaxurl;
}
},
but apart from that i got everything working right. What do you think?