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
    Facebook Open Graph META Tags

    It's no secret that Facebook has become a major traffic driver for all types of websites.  Nowadays even large corporations steer consumers toward their Facebook pages instead of the corporate websites directly.  And of course there are Facebook "Like" and "Recommend" widgets on every website.  One...

  • By
    Create a CSS Flipping Animation

    CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there's...

Incredible Demos

  • By
    Six Degrees of Kevin Bacon Using MooTools 1.2

    As you can probably tell, I try to mix some fun in with my MooTools madness but I also try to make my examples as practical as possible. Well...this may not be one of those times. I love movies and useless movie trivia so naturally I'm...

  • By
    Pure CSS Slide Up and Slide Down

    If I can avoid using JavaScript for element animations, I'm incredibly happy and driven to do so.  They're more efficient, don't require a JavaScript framework to manage steps, and they're more elegant.  One effect that is difficult to nail down with pure CSS is sliding up...

Discussion

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