I am new to AngularJS to JS in general. Now I want to use JSTestDriver and behavior driven development framework Jasmin . As I understood AngularJS works with Jasmine and test driver. I am working with Ideal Intellij 11.1.3. I added the plug in for JsTestdriver to It and run some test as described here http://code.google.com/p/js-test-driver/wiki/IntelliJPlugin. Now here is the problem. When I write some Jasmine tests like this one
describe("A suite", function() {
it("contains spec with an expectation", function() {
expect(true).toBe(true);
});
});
, for the first time indea intellij asked me to download the jasmine adapter and I did, but when I run the test I got this message : unable to attach test reporter to test framework intellij. I searched google for solutions, some guy posted how to run the angular tutorials: here : https://groups.google.com/forum/?fromgroups=#!topic/angular/LdjNsZD69Uk.
he uses a configuration files that comes with Angular js. and Node.js should I install them too ? isn't there any way to automatically do this from ideal intellij ?
What files structure should I have ?
Any help, link or suggestion will be great.
I fixed my jsTestDriver.conf file and it's paths, but now I get this problem :
Testing started at 1:31 PM ...
Cannot read [
/tmp/.m2/repository/org/testng/testng/6.7/testng-6.7.jar!/testng-reports.js
/home/clouway/.m2/repository/org/testng/testng/6.7/testng-6.7.jar!/testng-reports.js
] derived from .m2/repository/org/testng/testng/6.7/testng-6.7.jar!/testng-reports.js
Cannot read [
/tmp/.m2/repository/org/testng/testng/6.7/testng-6.7.jar!/jquery-1.7.1.min.js
/home/clouway/.m2/repository/org/testng/testng/6.7/testng-6.7.jar!/jquery-1.7.1.min.js
] derived from .m2/repository/org/testng/testng/6.7/testng-6.7.jar!/jquery-1.7.1.min.js
at com.google.jstestdriver.PathResolver.resolve(PathResolver.java:98)
at com.google.jstestdriver.config.ParsedConfiguration.resolvePaths(ParsedConfiguration.java:99)
at com.google.jstestdriver.config.Initializer.initialize(Initializer.java:86)
at com.google.jstestdriver.embedded.JsTestDriverImpl.createRunnerInjector(JsTestDriverImpl.java:368)
at com.google.jstestdriver.embedded.JsTestDriverImpl.runConfigurationWithFlags(JsTestDriverImpl.java:342)
at com.google.jstestdriver.embedded.JsTestDriverImpl.runConfiguration(JsTestDriverImpl.java:233)
at com.google.jstestdriver.idea.TestRunner.runTests(TestRunner.java:195)
at com.google.jstestdriver.idea.TestRunner.executeTestCase(TestRunner.java:131)
at com.google.jstestdriver.idea.TestRunner.unsafeExecuteConfig(TestRunner.java:122)
at com.google.jstestdriver.idea.TestRunner.executeConfig(TestRunner.java:97)
at com.google.jstestdriver.idea.TestRunner.executeAll(TestRunner.java:88)
at com.google.jstestdriver.idea.TestRunner.main(TestRunner.java:330)
Empty test suite.
I Use maven as my build tool.
I haven't used JSTestDriver in IntelliJ, so I can't address your question directly. However, AngularJS has moved from JSTestDriver to using Testacular (http://vojtajina.github.com/testacular/), so you might want to do the same. The link includes some setup help getting it running in WebStorm which should be the same.
Looks like he's renamed it "Karma" (http://karma-runner.github.com/)
Related
In my AngularJs application I'm using Jasmine and Karma for my unit tests.
Recently, after a chrome update (now on 72.0.3626.81) my unit tests starting failing locally (with no change to code). I believe the error is a result of my coverage tool Instanbul.
Sometimes the error appears like this:
An error was thrown in afterAll Uncaught ReferenceError: __cov_iuQO6FdumXRPLjSMopb0JQ is not defined thrown
Other times it will appear within a specific unit test (not sure why).
I searched my application and the only file this __cov_ variable could come from is the return of a function within the Instanbul package, generateTrackerVar() within instrumenter.js.
As no code changes were made I assume that the issue is with the new version of Chrome, perhaps the security settings.
My question what permissions would karama-coverage/istanbul require? OR if anyone suspects the issue isn't security based, then what could be causing this error?
Thanks
EDIT:
I have tried to disable web security in my gulpfile like so:
browsers: [ 'Chrome_without_security' ],
customLaunchers: {
Chrome_without_security: {
base: 'Chrome',
flags: ['--disable-web-security']
}
},
But this didn't solve the issue. Is there a way to set the chrome version in this config?
I managed to solve this by figuring out the hashcode after __cov_ was related to a test file that was throwing an error. I don't know why the error didn't just appear as it normally would, that will be another problem to solve.
For now I managed to figure out the file by logging in instrumenter.js within the instanbul package. Then by removing my coverage tool I figured out the source of the issue. Simply removing the coverage tool would give me a different error but not tell me which file so I needed to do both.
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!
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.
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.
I'm trying to setup my AngularJS application to test out controllers, routes, templates and so on, but I'm having an issue getting some of the helper methods provided by the angular-mocks.js to work (namely module and inject).
I'm using testacular to load up the test suite with the following files added before the specs:
files = [
MOCHA,
MOCHA_ADAPTER,
'../application/lib/angular.min.js',
'./lib/angular/angular-mocks.js',
'./lib/angular/angular-scenario.js',
'../application/application.js',
'./lib/chai.js',
'./lib/chai-should.js',
'./lib/chai-expect.js',
'./spec/**/*.js'
];
So far so good, but when I run the tests I get this issue:
ReferenceError: Can't find variable: module
Not sure where this is loaded. Am I missing something?
First thing to check is that all those files are getting loaded in the test browser. It's surprisingly easy to get a path wrong in your config and not realize it. If you're running testacular with autowatch, you can navigate to http://localhost:9876/context.html with a browser and use developer tools inspect elements/resources/network and see if anything is missing.
If everything is good there and you're still having problems, post some of your test code and I'll take a look.
UPDATE: It appears (strangely) from the comments in the source for angular-mocks.js (line 1635) that window.module is only available with Jasmine. It looks like you're using Mocha instead of Jasmine. This is very likely the culprit.
ANSWER:
I can't rightly take credit for this Matsko, since you figured it out yourself... but it turns out that the current AngularJS stable download and angular-seed contain an older version of ngMock that doesn't support Mocha. Manually replacing the mock file with the latest from the github repo solves the problem. Glad I could help ;-)
I ran into this issue today and I wanted to provide others with a complete summary of the required steps to get this working. First let's say you have a module named myApp. Inside that that module there is a service called myModel. the myModel service has a method named getItems().
Currently, the angular-mocks.js (I am using AngularJS 1.0.6) does not support Mocha. You will need to visit this link and replace the 1.0.6 version with the one in the master branch from the AngularJS GitHub project. An easy way to do this (if you have wget) is wget https://raw.github.com/angular/angular.js/master/src/ngMock/angular-mocks.js in the correct directory. If you use a properly configured Sublime or vim it can also easily pull it down for you.
Make sure your karma.conf.js file includes the angular-mocks.js file in files array
Somewhere in your tests.js file (maybe at the top level describe) include beforeEach(module('myApp')); or whatever you named your main module.
If you plan to use the service (or whatever you want to include in the test) in more than one place you can call another beforeEach where needed like this:
beforeEach(inject(function(myModel) {
mymodel = myModel;
}));
otherwise you just can inject where it is needed. Now the mymodel variable (notice this is the variable you assigned in the beforeEach above) will be available to you for testing in your next blocks. For example, you can now write:
describe('when fetched', function() {
it('should return 3 items', function() {
// console.log(mymodel.getItems());
expect(mymodel.getItems()).to.have.length(3);
});
});