FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

JsObjects/JavaScript/UnitTests/JasmineRequireJs at master · charliecalvert/JsObjects · GitHub

Latest commit

 

History

History

README.md

Jasmine Require Js

by Charlie Calvert

Testing

I've created a sample project to help you see how to test and use require. It is called JasmineRequireJs and is hosted on JsObjects.

Looking at that project, see this part of karma.conf.js:

frameworks: ['jasmine', 'requirejs'],

files: [
    'public/components/jquery/dist/jquery.min.js',
    'node_modules/jasmine-jquery/lib/*.js', {
        pattern: 'spec/test-*.js',
        included: false
    }, {
        pattern: 'public/javascripts/**/*.js',
        included: false
    },
    'spec/main-test.js'
],

// list of files to exclude
exclude: ['public/javascripts/main.js'],

Note the exclusion of public/javascripts/main.js and inclusion of spec/main-test.js that there are no frameworks loaded at the very bottom of the file.

I use test-XXX.js as the naming convention for require based tests, and spec-XXX.js for jasmine server side tests.

Look at this sample main-test.js file:

function loadTestsIntoArray() {
    'use strict';
    var tests = [];
    for (var file in window.__karma__.files) {
        if (/test-/.test(file)) {
            console.log('Loaded test:', file);
            tests.push(file);
        }
    }
    return tests;
}

require.config({
    baseUrl: '/base',

    paths: {
        home: 'public/javascripts/home'
    },
    deps: loadTestsIntoArray(),
    callback: window.__karma__.start
});

Look at the way we wrap our tests in a require define function:

define(['home'], function(home) {
    'use strict';

    describe('Elvenware Simple Plain Suite', function() {

        it('expects true to be true', function() {
            expect(true).toBe(true);
        });

        it('expects home.color to be red', function() {
            expect(home.color).toBe('red');
        });

        it('expects home.size to be big', function() {
            expect(home.size).toBe('big');
        });
    });

});

Back | FazBrowse Home | New Git URL