Resharper 9 and Jasmine 2.x references - angularjs

in the past I have used webstorm, karma, jasmine and phantom to run js tests. I have to now run tests within VS2015 and opted for resharper/jasmine and phantom js. I have my tests running ok and its actually looking good. The only gripe I have is that with karma you could specify wild card references and hence using a config all the referenced dependent js files are in one location. Now Im having to specify references in every spec file that I create. Is there an better way of doing this?
e.g. at the top of my spec file I have a couple of these:
///<reference path="~/Scripts/jasmine/jasmine.js"/>
///<reference path="~/Scripts/jasmine/jasmine.js"/>
///<reference path="~/Scripts/jasmine/jasmine-html.js"/>
///<reference path="~/Scripts/jasmine/boot.js"/>
///<reference path="~/Scripts/angular-core/angular.js"/>
and each file has much of the same references copied and pasted.
As a side note - I have also noticed that under the scripts folder in my mvc app there is an auto gen _references.js file that seems to have all my referenced files in it (though some paths are relative) - not sure that that is!
thanks

First off, R# 9.2 automatically loads in the needed jasmine files, so they're not necessary as references, and additionally if you load e.g. 2.3 jasmine as references, it breaks the css on the displayed page.
What I found that works well is to create a testReferences.js with the stuff I want in all unit tests, and then reference it with additional references.
testReferences.js:
/// <reference path="~/wwwroot/lib/angular/angular.js" />
/// <reference path="~/wwwroot/lib/angular-mocks/angular-mocks.js" />
/// <reference path="~/wwwroot/app/app.js" />
Unit Test:
/// <reference path="~/scripts/testReferences.js" />
/// <reference path="~/wwwroot/app/Production/productionQueueController.js" />

Related

AngularJS intellisense not working on Visual Studio 2015

According to this post intellisense should also be working on the new VS 2015, but so far I only get intellisense for the angular object and not for the dependencies or my custom modules.
Here's what I did:
Added the angular.intellisense.js to the global javascript references at C:\Program Files (x86)\Microsoft Visual Studio 14.0\JavaScript\References
Restarted VS2015
And then nothing, it just showed exclamation marks whenever I tried to use intellisense on a $http object.
I also added the file to the same place as my angular.js but it still didn't work. The question that I have in this case is, where should I place the file? on the angular public folder with only my angular.js, or on my dev angular folder where all the files downloaded from bower are.
I also tried addind it directly into the tools/options/text editor/javascriptr/intellisense/reference menu, on the Implicit(Web) reference group, but it still didn't work.
On my project I have the following folder structure inside the src folder:
wwwroot
app (my angular site stuff)
controllers
services
views
lib (js dependencies, only the .min.js file of each library)
angular
angular-route
....
_references.js (the visual studio js references file, contains reference to the files inside the app and lib folders)
Libraries (contains the full libraries as downloaded by bower)
angular
angular-route
...
As a side note, I don't have a /scripts folder and therefore no /scripts/_references.js file
.
This was not working for me in Visual Studio 2015 RTM in a web project, but I solved the problem.
This project was not created with Visual Studio and does not have a _references.js file anywhere. So I think this will work in any situation.
I removed all other intellisense resources from within the VS UI to make sure what I did was what fixed it.
Go to https://www.angularjs.org and pull up the download dialog box.
Copy the Uncompressed CDN url. Today that happens to be https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js
In Visual Studio 2015 RTM, go to Tools, Options, Text Editor, Javascript, Intellisense, References. Choose the appropriate Reference Group; for most web project this is Implicit (Web). Paste the url at the bottom text box and click the Add button. Don't dismiss the dialog box yet.
Under Text Editor, Javascript, Intellisense, General, make sure the check box is checked for Download remote references.
Click the OK button.
(optional) If you want intellisense for the angular providers that you create (not part of the angular framework), add _references.js to the root of your project. Don't bother making a Scripts folder. Right click on it and choose auto-sync, then choose update. Go into it and remove any js files created by a build process. If you don't, they can be so large they will break intellisense. Be prepared for a ~5-10 second delay the first time you use intellisense, as it has to load all these references from your project.
You may need to disable intellisense in Resharper for javascript if it interferes with the native intellisense.
Restart Visual Studio. It will not work until you do this. Also, I'm paranoid about closing all other instances other than this instance first, so these settings "stick". So I suggest you do that before restarting this instance.
As #Balthasar pointed out (and in case you are using Resharper) you will need to enable intellisense from Visual Studio for it to work:
Resharper -> options -> environment -> intellisense -> general, select 'Custom Intellisense' and for Javascript you can select Visual studio. Alternatively you can use the 'Visual Studio' statement completion (second option)
i've just realized that the automatic order that _reference.js file uses (first my files then the framework's files) prevented intellinsense to work on other files that weren't the app.js file
this is how it now my _references.js looks like:
/// <autosync enabled="false" />
/// <reference path="angular.js" />
/// <reference path="angular-resource.js" />
/// <reference path="angular-ui-router.min.js" />
/// <reference path="jquery-2.1.4.js" />
/// <reference path="materialize/materialize.js" />
/// <reference path="../App/App.js" />
/// <reference path="../App/Controllers/productsController.js" />
/// <reference path="../App/Controllers/productsEditController.js" />
/// <reference path="../App/Controllers/valuesController.js" />
/// <reference path="../common/common.services.js" />
/// <reference path="../common/productsResource.js" />
/// <reference path="../common/valuesResource.js" />
I had a similar issue and it turned out Resharper was blocking all the nice JavaScript intellisense I had setup in my _references.js file.
Visual Studio intellisense for AngularJS is extremely sentimental (a nice way of saying that it's most likely poorly developed).
So, even if everything is well configured with the _references.js file, and you get intellisense for other libraries like jQUERY, you will most probably not get it for AngularJS.
For example, in VS 2015 community, the below directive will not show intellisense for the $http angular object, although everything works fine with the code:
In the image below, I add an empty array to the module (which means that the module will get created, and if another with the same name exists, it get overwritten), and intellisense starts working:
Here is a snippet of the code for you to test yourself (try and add the empty array here):
(function () {
'use strict';
angular
.module('intellisence.sucks.directives')
.directive('footer', footer);
footer.$inject = ['$http'];
function footer($http) {
$http.
var directive = {
link: link,
restrict: 'EA'
};
return directive;
function link(scope, element, attrs) {
}
}
})();
PS: If you click on any folder on you project in the Solution Explorer and press Ctrl+Alt+A to add a new item, you get suggestion to add a AngularJs Directive, and If you do it, the Directive will be like the one I just showed you, without the empty array on the module declaration, so intellisence won't work with it. It won't work with the example that Microsoft gives to the users... Only works on the module creation, your first file and doesn't work from now on.
I had the same issue. When I added angular, VS 2015 (RTM) modified my _references.js; basically it removed some of my lines in the file. When I added a reference for angula in my _references.js as below
/// <reference path="lib/angular/angular.js" />
I got my intellisense for Angular 1.4.3 in VS 2015!
Follow this article to add more comprehensive intellisense to VS.
http://blogs.msdn.com/b/visualstudio/archive/2015/02/05/using-angularjs-in-visual-studio-2013.aspx
Download the angular.intellisense.js file and place it in the Program Files (x86)\Microsoft Visual Studio 12.0\JavaScript\References folder
i had this issue.
The visual studio IDE will scan any js files referenced in the HTML files and use them if neccesary (for the intellisense etc).
My problem was i was referencing Angularjs using the CDN/http:// addresses and thus Visual studio did not have any information on angular.
Try downloading the angularjs js file directly and include in your project and reference in your index.html, rebuild (just in case) and try again and hopefully it should work.
Hope i helped.
I have this issue for RTM ..apart from angular object and in a hello world complexity senario ($http and all custom objects dont work) .. Followed the _references setups . My only suspicsion is I upgraded from RC to RTM (no fresh install) have created a issue on Git [link]github.com/jmbledsoe/angularjs-visualstudio-intellisense/issues/… ..Grabbing a VHD Win 10 image and going to try that once the d/l finishes :( –
UPDATE
Ok with a bit of help here is teh answer .... The Intellisense engine never sees the module named "sportsStore" being created, since it is created in the app.html file in a script block:
<script>
angular.module("sportsStore", ["customFilters","cart"]);
</script>
The VS Intellisense engine is "executing" the code in your project in order to discover how to do code completion. It's using the _references.js file as its starting point and executing each reference from that file, in order. Since VS Intellisense never executes a line of code that creates the AngularJS module named "sportsStore", it doesn't know how to do code completion.
Move the JavaScript code above into its own JS file (let's call it "app.js") and include a reference to it in _references.js. Make sure the "app.js" reference is immediately after the "angular.js" reference, since you need it to create the module before the other script files configure it. :D
Just create an _references.js file in a folder named 'Scripts' (naming convention) at the root of your project. Update it with your necessary javascript files and you should be able to get intellisense. Here's a link on why such a thing was needed: http://madskristensen.net/post/the-story-behind-_referencesjs
None of the above work for me. Mine is Visual Studio 2017 - Professional
Yet I got it working using my solution here -->
You have to reference the source by an enclosed /// <reference path="yourpath"/> even the source is in the same folder where you code is.
Do NOT USE minified source. All your source has to be non-minified.
If you store your path stmts in _reference.js file, make sure that file is at the same dir where your code file is.
Although I can put the reference stmt inside my code file, I chose to use a separate file "_reference.js" to store it.
You can put this with your code :
/// <reference path="../_assets/JS-Main/angular-1.3.13.js" />
var app = angular.module('app', ['ui.grid', 'ui.bootstrap']);
app.controller('MainCtrl', ['$scope', '$http', function ($scope, $http) {
Or you can enter this line into your _reference.js file
/// <reference path="../_assets/JS-Main/angular-1.3.13.js" />
After you have done all the above, you should be able to see the angular intellisense.
You can do the same thing for others' intellisense like jQuery, Anytime, _underscore, etc... just keep adding path statements into the _reference.js file and you can also copy that _reference.js file to other websites if they have the same dir struct. Good luck!

Difficulty with AngularJS "module" declaration in Typescript in Visual Studio 2013

I am attempting to use Typescript to build an Angular JS 1.3 app, and I am having trouble right out the gate because it says that "module" does not exist on"typeof angular".
I thought this was easily rectified by just including the "DefinitelyTyped" angular.d.ts file, but that doesn't seem to have done anything.
My folder structure looks like this...
application
assets
typings
angularjs
angular.d.ts
jquery
jquery.d.ts
app
app.core.ts
js
jquery
jquery.js
And my angular app.core.ts looks like this;
/// <reference path="~/application/assets/typings/jquery/jquery.d.ts" />
/// <reference path="~/application/assets/typings/angularjs/angular.d.ts" />
((): void => {
'use strict';
angular
.module('app', [
/*
* Angular Modules
*/
'kendo.directives',
'ui.bootstrap',
'ui.bootstrap.drawer',
'ui.check'
]);
})();
At first I just assumed the paths were wrong, but it doesn't seem to matter what paths I use. If I use paths relative to the app.core.ts file, it still doesn't work.
I am using Visual Studio 2013.4 Professional, and it looks like this on my screen;
Can anyone help me? I'm getting very frustrated already with angular.
The latest definition files use TypeScript 1.4 syntax. Please verify your IDE supports this version.

How do you reference external libraries with Jasmine + Resharper

I can run Jasmine unit tests from the Resharper 8.0 unit test runner.
I have a problem where any Javascript references that are normally in the html page (ie in my case Ext-Js) then I can't use the Resharper test runner, as you don't seem to have access to the HTML page that Resharper uses. (I assume it's generated as I could not locate it on disk)
I was thinking if there is a way to call or load your external library references from the Javascript test file directly instead of via the html page, then I could get this to work. I've not found if that is possible with Javascript (or Ext-Js) yet.
It seems the way to go at the moment is hardcoding include statements as special comments in the suite file (called doc-comments references), e.g.:
// include external files like so:
/// <reference path="/path/to/external-file.js" />
// than write your testing suite as usual:
describe('a silly suite', function() {
it('should test something is happening', function() {
expect(something).toBe('happening');
});
});
See this thread on the ReSharper community, as the source of this recommendation.
I wrote 2 repos for dealing with ExtJS 4 for unit testing using Karma test runner/ Jasmine 1.x and 2.0 versions and dealing with Async Issues: here they are: https://github.com/cgauthier/karma_jasmine_1_extjs4 and https://github.com/cgauthier/karma_jasmine_2_extjs4. The trick to loading external references is to add them as files in your modules declaration.

AngularJS unit testing with ReSharper

I'm trying to get Jasmine unit tests for an AngularJS controller running with the ReSharper test runner so I can run my client and server-side tests in one place within VS 2012.
I'm running into an issue where the ReSharper test runner is failing with a message of "Inconclusive: Test wasn't run". The same test runs fine using the test runner that comes with the AngularJS Seed project.
Here's my simple test for troubleshooting:
/// <reference path="~/Scripts/angular/angular.js"/>
/// <reference path="~/tests/test/lib/angular/angular-mocks.js"/>
/// <reference path="~/Scripts/app/controllers.js"/>
'use strict';
describe('controllers', function(){
beforeEach(module('myApp.controllers'));
it('should ....', inject(function() {
expect(1).toEqual(1);
}));
});
I suspect it has something to do with my references because if I remove the call to inject, my test runs fine. However, inject is defined in angular-mocks.js (which I'm referencing) so I'm not sure what the problem is.
Any suggestions?
Your hunch about ReSharper tripping over inline inject is right, it seems to expect function instead when it parses file to get list of tests. I've worked around by moving injects into either beforeEach or into the body of the it and that made ReSharper happy again. Btw, I've also added reference to jasmine.js at the top (before other references) to get rid of ReSharper's warnings about undefined Jasmine globals.
There is an issue about this ReSharper problem at their tracker at http://youtrack.jetbrains.com/issue/RSRP-383328 - you can vote for it to be fixed.
Take a look to this page. I disabled the option "Shadow-copy assemblies being tested", and it worked.
Test method is inconclusive: Test wasn't run. Error?
ReSharper set file jasmine.js after all references.
angular-mock.js will not find jasmine and will skip creation window.module and window.injec functions
I created jasmine2.js and set it as first reference. I did empty jasmine.js and set it as second reference.
After all my test did work

Silverlight unable to resolve References when switching from Debug to Release

I am using: Silverlight Version 4.0, 100% F# solution. I am having an issue when switching the Target Configuration from debug to release. Everything compiles fine in debug mode, then in release I get the following:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9):
warning MSB3245: Could not resolve
this reference. Could not locate the
assembly
"System.ComponentModel.DataAnnotations".
Check to make sure the assembly exists
on disk. If this reference is required
by your code, you may get compilation
errors.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9):
warning MSB3245: Could not resolve
this reference. Could not locate the
assembly
"System.Windows.Controls.Data.Input".
Check to make sure the assembly exists
on disk. If this reference is required
by your code, you may get compilation
errors.
The Item group in the project file lokos like:
<ItemGroup>
<Reference Include="FSharp.PowerPack">
<HintPath>C:\Program Files\FSharpPowerPack-2.0.0.0\Silverlight\v3.0\FSharp.PowerPack.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core">
<HintPath>$(ProgramFiles)\Microsoft F#\Silverlight\Libraries\Client\$(SilverlightVersion)\FSharp.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Net" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Browser" />
<Reference Include="System.Windows.Controls">
<HintPath>bin\Debug\System.Windows.Controls.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Controls.Data">
<HintPath>bin\Debug\System.Windows.Controls.Data.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Controls.Data.Input" />
<Reference Include="System.Windows.Controls.DataVisualization.Toolkit">
<HintPath>bin\Debug\System.Windows.Controls.DataVisualization.Toolkit.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Controls.Input">
<HintPath>c:\Program Files\Microsoft SDKs\Silverlight\v4.0\Libraries\Client\System.Windows.Controls.Input.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Controls.Layout.Toolkit">
<HintPath>bin\Debug\System.Windows.Controls.Layout.Toolkit.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Controls.Navigation">
<HintPath>bin\Debug\System.Windows.Controls.Navigation.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Controls.Toolkit">
<HintPath>bin\Debug\System.Windows.Controls.Toolkit.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Data">
<HintPath>bin\Debug\System.Windows.Data.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
</ItemGroup>
Obviuosly some Elements have HintPaths while others do not, and while some have hintpaths there appear to be absolute and relative paths...
Can anybody help me out? Thanks in advance.
OK so I removed the references and then readded them and they came into the project file in the format of:
c:\Program Files\Microsoft
SDKs\Silverlight\v4.0\Libraries\Client\System.ComponentModel.DataAnnotations.dll
for both of the references. It all compiles - in both versions. Any hint on th HintPaths? How they are used and how and when they are generated? And why when I tried to modify the proj file by hand it didn't seem to matter (still didn't compile even though VS told me it reloaded)?
Thx
Sounds like you moved the project from another machine and you don't have the Silverlight Toolkit and the WCF RIA Services installed on your machine.
Clean your solution, close your Visual Studio and install what's missing.
FYI, there is a bug in the shipped Microsoft.FSharp.targets that may interact with this. You can add this line
<FrameworkRegistryBase Condition="'$(TargetFrameworkIdentifier)'=='Silverlight'">Software\Microsoft\Microsoft SDKs\$(TargetFrameworkIdentifier)</FrameworkRegistryBase>
inside a <PropertyGroup> (just below the <Tailcalls> element is a good spot) inside Microsoft.FSharp.targets to fix it. I don't know if this relates to your problem (it sounds like it may not), but just a heads-up in case.
(The fact that you get a HintPath (even if you do things right) may also be the result of a bug in the F# project system.)
One possible strategy if you need a workaround is to check in a copy of DLLs you need to reference in a fixed spot (relative to your projects) under source control, and then reference those DLLs via the 'fixed' relative paths.

Resources