I would like to test my javascript code (that includes jQuery library) that is in my CShtml file at a MVC project that runs on visual studio 2015.
I know that testing on js files can be done using jasmine.
Can I test a cshtml file using jasmine?
Where can i find a good tutorial on the subject?
You could use Chutzpah. It is a JavaScript test runner which works fine with Jasmine. It is available as a plug-in for Visual Studio and is easy to setup. It also integrates with the Test Explorer of Visual Studio. The wiki explains the features and how it works.
The following thread can help you:
Setup Jasmine Test Framework on MVC 5
This is a good read too
Related
I have a bunch of QUnit tests. I am testing my code against html templates. For these tests I am using HTML template importing feature.
I have the following on the top of the JavaScript test file.
///<template path="mytemplate.html" mode="script" id="mytemplate" type="text/ng-template" />
If I run the tests using the VS 2015 Chutzpah plugin, the tests run fine but they fail if I use ReShaper(ReShaper ultimate 10.2). ReShaper won't recognize the template reference.
Has anyone tried to get ReShaper to run QUnit tests by using templates ? If this is not possible on ReShaper, has anyone tried to access html files during there QUnit tests which will work with ReShaper ?
After looking at ReSharper documentation looks like Reshaper doesn't really support Chutzpah. ReSharper will run Jasmine and QUnit.
ReShaper will however work with a custom html harness which could be generated by chutzpah.
This is something that unfortunately doesn't work for me because the html templates could change during development.
Maybe QUnit has a way to inject html templates in QUnit fixture.
Im searching for a decent test runner and unit testing framework for Javascript. My candidates are Karma and Mocha. Previously I used JsTestDriver, where adding HTML fixtures was easy, but I cant find a way how to load HTML fragments and access it from Mocha tests using Karma testrunner
I have a demo that uses html fixtures with jasmine here and the demo description contains links to a screencast and github repo for running with Karma. See this link.
The final solution was Karma testrunner combined with RequireJS, which has a text plugin making the loading of HTML fixtures really easy.
A working example can be seen at this Minesweeper game. It's still in development phase, but the the libraries and structuring are working.
how do you integrate Jasmine's test runner with Visual Studio and your custom build process ? I've read an article at codebetter that shows how to achieve this task using FubuMVC and a few other components but I was wondering if you can recommend any alternatives ?
So how do you do that at your workplace ?
Many thanks,
Tomek
Take a look at Chutzpah (http://chutzpah.codeplex.com/). It has integrated test runners and command line options for running Jasmine or QUnit tests. Behind the scenes it uses PhantomJS, a headless browser, to load up tests and run them.
I know this is a year old, but FYI, I noticed that a new AngularJS SPA Template project (ASP.NET) in Visual Studio 2013 includes Jasmine (SpecRunner.cshtml). The AngularJS SPA Template is an extension to VS2013 (and can be installed on VS2012 and VS2010).
So it is there now, go to extensions and updates in VS to find it!
I'm trying to use the jasmine-jquery plugin: https://github.com/velesin/jasmine-jquery. In the documentation it says to:
Simply download jasmine-jquery.js from the downloads page and include
it in your Jasmine's test runner file (or add it to jasmine.yml file
if you're using Ruby with jasmine-gem). Remember to include also
jQuery library as jasmine-jquery relies on it.
I'm trying to use this plugin to add fixtures to my jasmine tests in coffeescript for a coffeescript one page HTML5 canvas application. I'm using the jasmine-node version of jasmine to run my jasmine tests using node.js My issue with the above instructions is that I do not see a jasmine test runner file to edit, and as a result I'm unable to call methods from this plugin such as load_fixtures in my specs.
My current directory structure for the project is
coffescript/shape.coffee
index.html (An html file I would ideally like to use for my tests)
javascript/shape.js (The outputted coffeescript)
spec/shape.spec.coffee
spec/jasmine-jquery-1.3.1.js (The plugin)
Any insight is greatly appreciated as I've spent several hours trying to get this to work correctly. If you know a different test framework with fixtures that would be easier to setup for a coffeescript project that was also be welecomed. Thanks!
The library you are trying to use assumes that you are using jasmine in a html page. Neither it nor jquery will work with jasmine-node.
jQuery cannot work on node because it needs the browser's DOM api. There are some libraries that mock the DOM for node that might give you what you need.
The test runner file you refer to is included in the standalone version of Jasmine (SpecRunner.html). It is not part of Jasmine-node.
I am looking for a unit testing framework to use with javascript that integrates well with Rails 3.0
Anyone with experience with above frameworks can share their experience?
** UPDATE: JSpec is now discontinued as per their Github repository: http://github.com/visionmedia/jspec so this leaves Jasmine and QUnit
Jasmine works just fine with Rails 3, check out for how to integrate it: http://pivotallabs.com/users/dwfrank/blog/articles/1427-jasmine-in-rails-3
Check out the qunit for rails plugin if you use Qunit.
I've used QUnit on projects written in .NET and Java. In both worlds, we had to homebrew the integration. I don't expect Rails integration to be any more forthcoming.