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

  • By
    Responsive Images: The Ultimate Guide

    Chances are that any Web designers using our Ghostlab browser testing app, which allows seamless testing across all devices simultaneously, will have worked with responsive design in some shape or form. And as today's websites and devices become ever more varied, a plethora of responsive images...

  • By
    JavaScript Promise API

    While synchronous code is easier to follow and debug, async is generally better for performance and flexibility. Why "hold up the show" when you can trigger numerous requests at once and then handle them when each is ready?  Promises are becoming a big part of the JavaScript world...

Incredible Demos

  • By
    Using Dotter for Form Submissions

    One of the plugins I'm most proud of is Dotter. Dotter allows you to create the typical "Loading..." text without using animated images. I'm often asked what a sample usage of Dotter would be; form submission create the perfect situation. The following...

  • By
    Facebook-Style Modal Box Using MooTools

    In my oh-so-humble opinion, Facebook's Modal box is the best modal box around. It's lightweight, subtle, and very stylish. I've taken Facebook's imagery and CSS and combined it with MooTools' awesome functionality to duplicate the effect. The Imagery Facebook uses a funky sprite for their modal...

Discussion

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