jasmine

How to Load a File for Testing with Jasmine Node?

这一生的挚爱 提交于 2019-12-02 22:12:43
I have a simple JavaScript file, color.js , and a matching spec file, colorSpec.js . color.js: function Color() { } colorSpec.js: require('./color.js'); describe("color", function() { it("should work", function() { new Color(255, 255, 255); }); }); When I run jasmine-node colorSpec.js , I get the following exception: ReferenceError: Color is not defined How can I get Jasmine to load my color.js file before running colorSpec.js ? you could load your color.js in the colorSpec.js with a require(). I dont see how jasmine can guess all the dependencies without you telling jasmine what they are

Use jasmine to test Express.js

寵の児 提交于 2019-12-02 22:12:28
I am learning Node.js and Express framework. I am a big fan of jasmine. So I want to use jasmine whenever I can, however, I can't find a good way testing Express with jasmine. For example, how should I test a route in app.js? If I have this route in app.js: app.get('/', function(req, res) { ... }); How can I use jasmine to test it? Jasmine-node makes it easy to use jasmine with node.js. There are some examples on their site. Another example can be found from http://blog.drewolson.org/post/14684497867/ web.archive.org You should try out http://frisbyjs.com/ I haven't had a chance to use it, but

How do I fix my generator-angular project so that grunt test works?

我与影子孤独终老i 提交于 2019-12-02 21:56:12
I am working off of this tutorial: http://www.sitepoint.com/kickstart-your-angularjs-development-with-yeoman-grunt-and-bower/ as a means to understand what files are created using yo generator-angular. I have experience using AngularJS, but was looking for a way to get a best-practices directory set up; I am not sure how to set up dependencies and get karma running on my own, hence using the yeoman generator. However, straight out of the box, without editing anything else, when I run grunt test I get the following: running "clean:server" (clean) task Cleaning .tmp...OK Running "concurrent:test

Getting “$digest already in progress” in async test with Jasmine 2.0

两盒软妹~` 提交于 2019-12-02 21:47:39
I know that calling $digest or $apply manually during a digest cycle will cause a "$digest already in progress" error but I have no idea why I am getting it here. This is a unit test for a service that wraps $http , the service is simple enough, it just prevents making duplicate calls to the server while ensuring that code that attempts to do the calls still gets the data it expected. angular.module('services') .factory('httpService', ['$http', function($http) { var pendingCalls = {}; var createKey = function(url, data, method) { return method + url + JSON.stringify(data); }; var send =

How can i test a AngularJS provider?

こ雲淡風輕ζ 提交于 2019-12-02 21:03:59
I need to test my own angular provider, and I need to test it in both config and run phase to check that config methods work and that the instantiated provider is indeed configured with the correct parameters. When I ask dependancy injection for the provider, it can't find the APIResourceFactoryProvider, only the APIResourceFactory, and I haven't found any examples of this on the repositories I've looked trough so far. Josh David Miller It's actually a lot simpler than it would at first seem to test a provider in AngularJS: describe('Testing a provider', function() { var provider; beforeEach

Spy on the result of an Observable Subscription with Jasmine

元气小坏坏 提交于 2019-12-02 20:49:09
问题 I am Jasmine unit testing an angular component, which uses Observables. My component has this lifecycle hook that I am testing: ngOnInit() { this.dataService.getCellOEE(this.cell).subscribe(value => this.updateChart(value)); } I have a test that ensures that getCellOEE has been called, but now I want to check that updateChart is called when the observable resolves with a new value. This is what I have so far: let fakeCellService = { getCellOEE: function (value): Observable<Array<IOee>> {

Using toThrowError in Jasmine

末鹿安然 提交于 2019-12-02 20:48:27
I am working on an app that makes heavy use of JavaScript. I need to unit test this code. In an effort to do that, I'm relying on Jasmine. Some of my JavaScript code throws JavaScript Error objects. Those objects assign values to the message and name property of the Error object. I assign a type of exception to the name property. For instance, sometimes the name is set to "OutOfRangeException", sometimes its "ArgumentException", etc. How do I use the toThrowError function in the Jasmine framework to test if a thrown error has a specific name? Currently, my JavaScript looks like the following:

Mocking modules in Node.js for unit testing

▼魔方 西西 提交于 2019-12-02 20:40:43
I want to unit test some functions in a node.js module. I think that mocking a 3rd module would be helpful. In particular to avoid hitting the database # models/account.coffee register = (email, password)-> sha_sum.update(password) pw = sha_sum.digest('hex') user = email: email password: sha_sum.digest('hex') users_db.save user, (err, doc)-> register_callback(err) account_module = register: register module.exports = account_module This is the module that i want to test # routes/auth.coffee account = require '../models/account' exports.auth = post_signup: (req, res)-> email = req.body.email

Jasmine in a separate test project

£可爱£侵袭症+ 提交于 2019-12-02 20:21:15
Is it practical/possible to separate jasmine tests into a separate visual studio project? I am just getting started with angular, and am trying to write my tests before I start on the actual angular implementation. I will be writing my project in Visual Studio 2012 with the Chutzpah test runner , see this video . Currently, I am trying to figure out how to organize my folder structure. I know about angular-seed and yeoman, but those are ill suited to starting a .net project. I am assuming that since unit tests in Visual Studio are usually separated into a separate test project, by convention,

Redirect calls to console.log() to standard output in Jasmine tests

有些话、适合烂在心里 提交于 2019-12-02 19:55:19
I'm using Jasmine via the jasmine-maven-plugin, and I would like to see console.log() messages in the Maven build output. Is there a way to achieve this? If console.log() cannot be redirected, is there any other way to log from my tests so that they show up on the Maven build output? I'm running these tests on Jenkins in a headless fashion, and would like a means to get some debug output from the tests. Try console.info('foo') From the test javascripts. You can use: jasmine.log("I've got a big log."); NB: See douglas-treadwell's comment below. This refers to Jasmine 1.x. With Jasmine 2.0 just