stevegw (28) [Avatar] Offline
#1
Hi,

Started looking at Chapter 3 and has a few issues following

Basically manged to get Karma working but not able to understand or get the tests running .. I looked in the final solution and there is no agelloModelSpec.

I'm not familiar with Karma

This is what I believe was defined

describe('Service: angelloModel', function () {

// load the service's module
beforeEach(module('Angello'));
var modelService;
// Initialize the service
beforeEach(inject(function (angelloModel) {
modelService = angelloModel;
}));

describe('#getStatuses', function () {
// write tests for angelloModel.getStatuses here
it('should return seven different statuses', function () {
expect(modelService.getStatuses().length).toBe(7);
});
});
});

running

karma start karma.conf.js

I does not list any executed


config has

// list of files / patterns to load in the browser
files = [
JASMINE,
JASMINE_ADAPTER,
'js*.js',
'tests*.js'
];


// list of files to exclude
exclude = [
'karma.conf.js'
];

tried forward and backslash

I'm running Chrome in Windows 8


any thoughts etc.

Steve
shiften (4) [Avatar] Offline
#2
Re: Chapter 3.5.2 Testing Services
I just got to this section, and it appears that they don't mention the all the required files needed.

karma.conf.js needs angular.js AND angular-mocks.js defined before the app code or the tests. The following works for me:

files = [
JASMINE,
JASMINE_ADAPTER,
'js/libs/angular-1.0.7.js',
'js/libs/angular-mocks.js',
'js/**.js',
'tests/**.js'
];

The text doesn't seem to explain why the mocks are needed.
markstewie (2) [Avatar] Offline
#3
Re: Chapter 3.5.2 Testing Services
Thanks,

This really helped me.

The book definitely needs to state that at least the following are needed. I was stumped for quite a while!

files: [
'js/angular.min.js',
'js/angular-mocks.js',
'js/**.js',
'tests/**.js'
],
buffalobillion (20) [Avatar] Offline
#4
Re: Chapter 3.5.2 Testing Services
Thanks, this helped me as well.
royseto (6) [Avatar] Offline
#5
Re: Chapter 3.5.2 Testing Services
To the authors: Please add something in section 3.5.2 about the need to include angular-mocks.js (and also jquery.js and angular.js) in the Karma configuration. I've been working though MEAP V5, and it's been fairly smooth sailing until I got stuck on this and spent a couple hours Googling for solutions.

I looked at https://github.com/angularjs-in-action/angello/blob/master/karma.unit.conf as well, but it doesn't work with the current version of Karma (0.10.4), so I couldn't just clone the example repository to get the Karma tests running.

Thank you!
tombrokeoff (13) [Avatar] Offline
#6
Re: Chapter 3.5.2 Testing Services
another sticking point and this info helped immensely. thank you.
tombrokeoff (13) [Avatar] Offline
#7
Re: Chapter 3.5.2 Testing Services
It should be noted that there needs to be a closing parenthesis added to the code from the book in order to get the test checking for 'To Do' to execute properly.

I had to change this:

}).toContain('To Do');

To this:

})).toContain('To Do');
325939 (2) [Avatar] Offline
#8
I added these files, but now I'm getting the following error:

Cannot set property 'mock' of undefined


Why would this be?
325939 (2) [Avatar] Offline
#9
325939 wrote:I added these files, but now I'm getting the following error:

Cannot set property 'mock' of undefined


Why would this be?


Strangely enough, it seems that angular-min.js is required, not simply angular.js. I plopped in angular-min.js, and voila!
305880 (1) [Avatar] Offline
#10
Also of note... as of the new Git repos such as "angello-lite" the code has been refactored.

The model "angeloModel" is now "AngeloModel" in the refactored code. The references to writing the unit tests need to be updated.