Loading Static Templates for Intern Testing
I use Intern by SitePen for all of my JavaScript functional testing. Intern has loads of features other functional test frameworks don't and it's completely Promise-based -- something I got very used to when I used the Dojo Toolkit every day. Async test creation can be difficult but I find it very rewarding.
While writing destructive tests for the Mozilla Developer Network, I decided I wanted to load specific content to test. The first step is adding a new file with the sample content alongside my tests, but then I needed to know how to load that content alongside the other test dependencies. Since that file isn't a JavaScript object, we need to pull that dependency in a special way:
define([ 'intern!object', 'intern/chai!assert', 'intern/dojo/text!tests/fixtures/in-content.html' ], function(registerSuite, assert, contentTemplate) { // Use the contentTemplate string here... });
Adding intern/dojo/text!
before the file path allows the file to be loaded without being evaluated as JavaScript. You can prepend that string to load any file type and use it as text in the callback!