Skip to content

Instantly share code, notes, and snippets.

@deadcoder0904
Last active April 5, 2019 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deadcoder0904/fe5fc34dd2c5877d46672f43b33d1b18 to your computer and use it in GitHub Desktop.
Save deadcoder0904/fe5fc34dd2c5877d46672f43b33d1b18 to your computer and use it in GitHub Desktop.
Automate boring tasks with DOM Testing Library by Kent C Dodds

Automate boring tasks with DOM Testing Library by Kent C Dodds

Watch the video for which tasks to automate

function loadScript(filePath) {
// Create a script tag, set its source
var scriptTag = document.createElement("script");
// And listen to it
scriptTag.onload = function(loadEvent) {
// This function is an event handler of the script tag
console.log('The file has been loaded. Do something else.');
}
// Make sure this file actually loads instead of a cached version
// Add a timestamp onto the URL (i.e. file.js?bust=12345678)
var cacheBuster = "";
cacheBuster = "?bust=" + new Date().getTime();
// Set the type of file and where it can be found
scriptTag.type = "text/javascript";
scriptTag.src = filePath + cacheBuster;
// Finally add it to the <head>
document.getElementsByTagName("head")[0].appendChild(scriptTag);
}
window.loadScript = loadScript;
// USAGE 👇
// loadScript('https://unpkg.com/dom-testing-library@3.16.8/dist/dom-testing-library.umd.js')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment