So, I was trying to figure out how front end testing (unit testing) works, but I was stuck at some point.
So, I have installed my jasmine test as follows:
describe('Blabla', function () { it('returns true', function () { var people = require(["people"], function(ppl) { return ppl; }); expect(people.getTitle()).toBe('People piolmjage'); }); });
But it makes me:
TypeError: undefined is not funtion
So people are undefined. So maybe my callback comes too late. But if I remove the callback, I get the following error:
it('returns true', function () { var people = require("people"); expect(people.getTitle()).toBe('People piolmjage'); });
Error: module name "people" has not yet been loaded for context: _. Use require ([])
I suppose something is wrong in my setup ... Does anyone know how to make this FE testing work?
I managed to get it to work from the console and use define in conjunction with phantomjs and durandal test files, but I need it to work outside the console, and therefore I can not use this define because the winner of the test won Do not find my tests.
This is why I need to use CommonJS to get the required view modes.
people model
define([], function () { var getTitle = function() { return "hello"; } var peopleViewModel = { title: 'People page', getTitle: getTitle }; return peopleViewModel; });
UPDATE
I got the code, but not with resharper. Follow this page from the durandal web page .
But this gives me console output, which is unstructured for actual reading.
However, I can use the define keyword, and then it works fine. So I guess the keyword requires , where did I mess up something?
UPDATE 2
So I used a violinist to check what was happening. I also finally got his job (kind of ...).
My test file now looks like this:
///<reference path="../../Scripts/require.js"/> ///<reference path="../../test/lib/jasmine-2.1.3/jasmine.js"/> ///<reference path="../../App/viewmodels/people.js"/> describe('Blabla', function () { it('require test', function (done) { require(['people'], function (people) { expect(people.title).toBe('People page'); done(); }); }); });
And then I changed the people file:
define("people", ["bla"], function (bla) { return { title: 'People page', bla: bla }; });
As you can see here, I name my viewmodel will be people . This works for testrunner, but in fact it does not receive files through requireJS , but only reference paths. In addition, this does not meet my needs, as the durandal models are unnamed .
Screenshot screenshot Fiddler:

So basically it doesn’t use requireJS to get view models, and therefore I can’t just use the require.config initializer to go to my view modes and load each model with requireJS. Any thoughts?