Meteor AngularJS templates (unit testing) - angularjs

How to test angular directives with Meteor? In a normal app, I have karma.conf.js with html2js preprocessor, but in meteor it's different (packages).
Now i have something like this: https://github.com/Nitrooos/Forum-Steganum/tree/templates, but i got Unexpected GET "client/posts/postsList/postsList.directive.html" error.
I tried with this package https://atmospherejs.com/sanjo/angular-templating, but I can't find any example how to configure it.

I resolved it. Now I'm making unit tests via gulp, server tests are via velocity.
An example you can find in this repo: https://github.com/SuperGrupa/Forum-Steganum
Hope it will help.

Related

Is it possible to use Jasmine without Karma for testing Angular/Node based Nw.js apps?

I've read ton's of tutorials, but I must admit that this testing stuff is still very confusing to me. I have a Nw.js app which (of course) uses NodeJS and also Angular. I've installed the Jasmine test framework globally via npm and wrote an example test which starts with the following lines, and placed it in the spec sub-directory:
describe ( 'Test for my controller', function () {
beforeEach ( module ('module_under_test') );
... and so on ...
});
When running the test by typing jasmine on the cmd line (from the root folder of the app), I get the following error message:
TypeError: module is not a function
I know that I have to include the Angular library somehow. But where? In a normal browser application, it is included in the HTML <script> tag, but I don't have this possibility. I also know that I could write a HTML file, which shows the Jasmine result page after tests have finished, but I would prefer to start Jasmine on the cmd line.
First I thought about adding the angular library to the "helpers" entry in jasmine.json. But it didn't work. The documentation of this file is unfortunately very poor. In the Angular documentation and tutorials it is always mentioned to use Karma. But my understanding is that Karma is only useful for testing with browsers, since it spawns an own webserver. This does not make sense in my case.
Would be great if somebody could give me a hint, thanks!

Angular 1.x Browserify Jasmine how to set up code coverage test?

I am using Angular (1.x) with Browserify, and Jasmine as test framework. I would like to run code coverage test. I researched online and it's a little here and there and some of the examples doesn't work. I was wondering if any people have the experience setting the code coverage test for angular+browserify+jasmine ? and if there's a repo in github i can reference?
Use karma-coverage. Check out my karma playground here: https://github.com/marcinmierzejewski1024/jasmine-karma-playground. It's propably based on istanbul(generated reports looks very similar) but I am not 100% sure

AngularJS unit test directly in browser with Jasmine but without Karma or nodejs or any test runners

We can test normal JavaScript code in the browser using only Jasmine (by only I mean without Karma or any other test runners or nodejs).
Can we do this for AngularJS projects as well? If yes, how?
Sure. It's exactly the same like with plain js. You just need to use the methods for angular testing.
Take a look at this post:
http://dennis-nerush.blogspot.co.il/2015/08/creating-masked-input-directive-with.html

Is there a generator for jasmine angular controller tests?

I'm looking for something that generates a boilerplate jasmine test for an angular controller. It seems you could pull the dependencies for the controller out and drop them into the spec and save some typing. I would be shocked if I were the first person to have this idea but I'm unable to find anything that does this, save a yeomen project that doesn't appear to work.
I've recently published my version of Angular JS unit test generator on npm - tleaf. Basically it tries to parse you source file looking for AngularJS units (controllers, services, etc) to extract information about unit name, module name and unit's dependencies. This information is used to create a unit test file, based on a template for this unit type. There is a default set of templates which have a pretty simple structure, it should be ok for general use. But it is also possible to create and use your own templates to generate unit test files. This is a very first version and I'll be happy to have any feedback.
I don't know of a generator for tests but I have two ideas.
Some editors provide templates for "repeated" code. Like Live Templates for Webstorm. There are multiple projects on github providing jasmine templates for it.
You could also check ng-describe. It removes the boilerplate and makes testing simpler. Here's an example form their github:
ngDescribe({
modules: 'A',
inject: ['$rootScope', 'foo'],
tests: function (deps) {
it('finally a test', function () {
deps.$rootScope.$apply();
expect(deps.foo).toEqual('bar');
});
}
});
I am using yeoman with generator-angular to generate our scripts & tests.
yo angular:directive myDirective
yo angular:service myService
yo angular:controller myController
etc..
will generate both the script and spec templates. I am using Karma and Jasmine.
You could also always write your own yeoman generator.
I found this thing and it does a lot of good gob:
https://www.npmjs.com/package/generator-yosapy

How to setup Jasmine with RequireJS?

I am having a problem to figure out how to setup Jasmine with modules from RequireJS.
Basically, I want to test a first view:
it("can load sandbox", function() {
var view = new ItemView();
node = view.render().el;
expect(node).toContain("<li>Test</li>");
});
I don't see that ItemView can be defined as Backbone view, or how to inject Backbone into my tests with requirejs. Now, I see some discussions on using testr.js on one hand, on the other hand, I've found a git repo that does a setup of SpecRunner.js : http://github.com/uzikilon/Todos.git
Ideally, I would just be running
rake jasmine
from my project directory, but how would should Jasmine and Require.js be talking to each other?
Many thanks if someone has feedback, eventually, with a pull request on this experimental repo: https://github.com/mulderp/backbone-require-test
Uzi Kilon, who is the author of the github repo you linked to, wrote an article about how to set the two up together, here.
The other part of your question seems to suggest you want to automate the running of the tests, one way to do that is using PhantomJS the headless webkit implementation. You'll find an article about that here
How is backbone.js is getting loaded in your ItemView? If you define require.js configuration that could be shared between your production code and Jasmine tests. Again there are different ways developers do to achieve this.

Resources