R#r 7 jasmine javascript unittest setup Follow
Do jasmine unit tests work in R#r 7 EAP? If so, can someone point me to info
on how to configure same?
I have been running my jasmine unittests with jsTestDriver.
R#r 7 recognizes the jasmine unittests and I can launch the test runner and the browser launches but no joy.
What does R#r use as the server for jasmine unit tests?
/jhd
Please sign in to leave a comment.
When running Jasmine tests browser window is intentionally left blank. All results are presented in ReSharper's Unit Test Session tool window. I'll add some kind of progress in browser as well later.
R# uses own custom web server to serve tests and collect results, it start every time you launch tests.
If you could provide sample of your tests, I could check if everything works correctly in your case.
Thanks info. I don't understand what 'context' / root the test runner/server is running under. These are configuration parameters to jsTestDriver. What is the fixture path?
jasmine.getFixtures().fixturesPath = '/test/app-test/fixtures';
---- directory structure---
+---Scripts
| +---app
| | +---page1
| | +---page2
| | +---base
| +---app-test
| | +---page1
| | +---base
| | +---page2
| | \---fixtures
| +---libs
| | +---crunch
| | +---min
| | \---testing
| | +---jasmine
| | +---jasmine-ajax
| | +---jasmine-jquery
| | | \---spec
| | | +---fixtures
| | | \---suites
| | +---jasmine-jstd
| | \---jasmine-stealth
| +---tools
---- simple test suite ----
describe('Staff template builder', function () {
var $html, staffViewmodelPhysicianRoles = {
"Physicians": [
{
"Code": "100",
"Name": null,
"Role": "Attending",
"IsHospitalist": false
},
{
"Code": "200",
"Name": null,
"Role": "Attending",
"IsHospitalist": true
}
],
"AvailablePhysicianRoles": [
{
"Key": "Admitting",
"Value": "Admitting"
},
{
"Key": "Attending",
"Value": "Attending"
},
{
"Key": "Emergency Room",
"Value": "EmergencyRoom"
},
{
"Key": "Surgeon",
"Value": "Surgeon"
},
{
"Key": "Anesthesiologist",
"Value": "Anesthesiologist"
},
{
"Key": "Consult",
"Value": "Consult"
}
]
};
jasmine.getFixtures().fixturesPath = '/test/app-test/fixtures';
jasmine.getFixtures().clearCache();
beforeEach(function() {
loadFixtures('episode-edit.templates.htm', 'episode-edit.harness.htm');
$html = templates.build('#physician-template', staffViewmodelPhysicianRoles);
});
describe('when populating physician role list', function () {
var options;
it('given N available roles there should be N entries in the list', function() {
options = $('.physician:first .physician-role', $html);
expect(options.length).toBe(staffViewmodelPhysicianRoles.AvailablePhysicianRoles.length);
});
//naive exact compare of options - input data === generated options list
it('role list exactly matches available roles', function () {
var normalizedOptions;
options = $('.physician:first .physician-role', $html);
normalizedOptions = _.map(options, function(item) {
return { Key: item.text, Value: item.value };
});
//works but no feedback on what actually failed
expect(_.isEqual(normalizedOptions,
staffViewmodelPhysicianRoles.AvailablePhysicianRoles)).toBe(true);
});
});
//hospitalist flag
describe('when populating the hospitalist flag', function () {
var hospitalistFlags;
beforeEach(function() {
hospitalistFlags = $('.physician .is-hospitalist', $html);
});
it('the first physician is not a hospitalist', function() {
expect(hospitalistFlags.first().is(':checked')).toBe(false);
});
it('the second physician is not a hospitalist', function() {
expect(hospitalistFlags.eq(1).is(':checked')).toBe(true);
});
});
//physician code/name
})
Can you supply a sample jasmine unittest that works?
bump
I tried changing the fixtures path but no joy. I still get '.... Test wasn't run' for all tests
jasmine.getFixtures().fixturesPath = '/app-test/fixtures';
I still don't have jasmine tests working. Cannot find any information.
/jhd
Hi John,
jasmine.getFixtures() and some other methods seem to be specific jsTestDriver code, that's why it fails in ReSharper.
You could reference your JavaScript code files via doc-comment references, e. g.
/// <reference path="path/to/code.js />
Hi Victor,
Thanks info, I'll give it a try and report back.
I'm working on a large single page app and are dozens, or more, files that have to be loaded. jsTestDriver supports a config file for defining the includes. Is there a similar capability in the R#r test runner?
/jhd
Hi Victor,
Progress... the following works w/o doc comments. This implies jasmine is 'baked in' to R#r, right? I'll see if I can get a real test to run next.
describe('resharper jasmine testrunner', function () {
describe('simplest possible test', function () {
it('should execute', function() {
expect(true).toBe(true);
});
});
});
Could I change the jasmine version using a doc comment?
BTW, is there any support for managing the 'includes'... config files or includes of '/// <reference path=""'?
/// <reference path="../../libs/testing/jasmine/jasmine.js"/>
/// <reference path="../../libs/crunch/jquery-1.6.2.js"/>
describe('resharper jasmine testrunner', function () {
describe('simplest possible test', function () {
it('should execute', function () {
expect(true).toBe(true);
});
});
});
Hi John,
yes, Jasmine runner is built-in. At the moment it's not possible to change its version, but I expect this feature to be available before 7.0 release.
What kind of support do you need for managing references?