Loading Static Templates for Intern Testing

By  on  

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!

Recent Features

Incredible Demos

  • By
    PHP Woot Checker – Tech, Wine, and Shirt Woot

    If you haven't heard of Woot.com, you've been living under a rock. For those who have been under the proverbial rock, here's the plot: Every day, Woot sells one product. Once the item is sold out, no more items are available for purchase. You don't know how many...

  • By
    Animated AJAX Record Deletion Using jQuery

    I'm a huge fan of WordPress' method of individual article deletion. You click the delete link, the menu item animates red, and the item disappears. Here's how to achieve that functionality with jQuery JavaScript. The PHP - Content & Header The following snippet goes at the...

Discussion

    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!