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
    Welcome to My New Office

    My first professional web development was at a small print shop where I sat in a windowless cubical all day. I suffered that boxed in environment for almost five years before I was able to find a remote job where I worked from home. The first...

  • By
    Send Text Messages with PHP

    Kids these days, I tell ya.  All they care about is the technology.  The video games.  The bottled water.  Oh, and the texting, always the texting.  Back in my day, all we had was...OK, I had all of these things too.  But I still don't get...

Incredible Demos

  • By
    Create a Context Menu with Dojo and Dijit

    Context menus, used in the right type of web application, can be invaluable.  They provide shortcut methods to different functionality within the application and, with just a right click, they are readily available.  Dojo's Dijit frameworks provides an easy way to create stylish, flexible context...

  • By
    Add Controls to the PHP Calendar

    I showed you how to create a PHP calendar last week. The post was very popular so I wanted to follow it up with another post about how you can add controls to the calendar. After all, you don't want your...

Discussion

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