Adding fixtures to jasmine/ Setting up Jasmine-Jquery - javascript

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.

Related

ReSharper support for QUnit tests doesn't recognize Chutzpah Template import feature

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.

What is the purpose of jasmine-node?

I can run my specs with either jasmine-node or just jasmine. They both run my specs. So, what value does jasmine-node add? The readme says:
This node.js module makes the wonderful Pivotal Lab's jasmine spec framework available in node.js.
https://github.com/mhevery/jasmine-node/blob/master/README.md
I don't understand. My app runs on node, my specs require node modules .. so when I run jasmine, I'm already using both node and jasmine. What does jasmine-node add?
I specifically am not asking for opinions about why jasmine-node is your favorite, or recommendations of other libraries. I only want to know, what is the purpose of jasmine-node?
The subtitle of jasmine-node is a good answer to your question:
DOM-less simple JavaScript BDD testing framework for Node
Let's go and look at the different parts of the answer:
DOM-less simple testing framework
jasmine is a JS testing tool. At the beginning JS was just for browsers. To give an output inside the browser there is this DOM Model, which is not so easy to use. Node.js gives you the possibility to run JS also on a server. On the server-side there is no DOM. To make things faster and easier you don't need a DOM implementation for your testing tool, when it just runs inside node.js
Jasmine itself is independent of a browser, so that is an intention for both jasmine and jasmine-node.
for Node
This is easy - jasmine-node is just for node and not for browser JS.
But behind that part there is the main purpose. Because the requirements between a brwoser test and a node.js test are totaly different. Because jamsine supports both ways it can not have all features, which are possible with node. If you look at the possible arguments at the documentation you see that there are much more options inside the CLI of jasmine-node. Some of the most interesting features are maybe:
Test a file automaticaly, when it changes
test coffeescript files directly
So to give you an answer to your question:
What is the purpose of jasmine-node?
jasmine-node provides you more CLI options for you tests. It can make some work automaticaly and it uses more of the node functions to provide that. So the future way for jasmine-node will be in providing more functions, which are just able to implement, when you just test on node.js

Node script modules how to properly reference within html

I'm putting together a solution with Node, Express and Angular. I've installed the node Angular package, but I'm not sure how to properly reference the library in my html. Do I need to configure a custom route outside of the public folder to achieve this?
Ideally, i'd like a solution that is analogous to the ASP.Net script bundle, where I can reference a named bundle, or Node script module in my html.
Edit
What I'm specifically trying to build right now is a test harness page that allows me to visualize Mocha unit tests, which necessitates client side script references to Mocha, Chai and Angular. It doesn't seem that keeping redundant copies of these libraries, or using a CDN reference for just the client side html is clean.
What is the best way to do this in Node?
The angular module in npm is for using angular server-side via jsdom. If you need it client-side for browsers, just download a copy from angular's website.
The only other way you could include the angular npm module client-side is if you were using browserify, which would also work.

How can I load HTML fixtures for Javascript unit tests in Karma with Mocha?

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.

Where should I store my Jasmine files in a Symfony project?

What is the best place to put the Jasmine files (libs, specs, SpecRunner.html)
in a symfony project?
I would make in this way:
the jasmine libs in web/vendor/js
the spec files in src/myProject/WebBundle/Resources/public/js
and the SpecRunner.html I have no idea.
Since Jasmine is used just for testing your JavaScript code, I don't think it is a good idea to put libraries and spec files in the public.
I would put them in src/myProject/WebBundle/Resources/
src/myProject/WebBundle/Resources/js/lib/jasmine
src/myProject/WebBundle/Resources/js/spec

Categories

Resources