jasmine

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

此生再无相见时 提交于 2019-12-03 08:14:36
问题 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

using Jasmines spyon upon a private method

梦想的初衷 提交于 2019-12-03 08:06:36
问题 is it possible to use Jasmine unit testing framework's spyon method upon a classes private methods? The documentation gives this example but can this be flexivble for a private function? describe("Person", function() { it("calls the sayHello() function", function() { var fakePerson = new Person(); spyOn(fakePerson, "sayHello"); fakePerson.helloSomeone("world"); expect(fakePerson.sayHello).toHaveBeenCalled(); }); }); 回答1: Just add a generic parameter < any> to the spyon() function: spyOn<any>

How to spy on anonymous function using Jasmine

↘锁芯ラ 提交于 2019-12-03 08:03:59
I'm using Jasmine to test my angular application and want to spy on an anonymous function. Using angular-notify service https://github.com/cgross/angular-notify , I want to know whether notify function have been called or not. Here is my controller: angular.module('module').controller('MyCtrl', function($scope, MyService, notify) { $scope.isValid = function(obj) { if (!MyService.isNameValid(obj.name)) { notify({ message:'Name not valid', classes: ['alert'] }); return false; } } }); And here is my test: 'use strict'; describe('Test MyCtrl', function () { var scope, $location, createController,

Angular Material MatTableDataSource cannot be found

匿名 (未验证) 提交于 2019-12-03 07:50:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to create a table using Angular Material Table , in the examples there is always the import: import {MatTableDataSource} from '@angular/material'; I'm trying to do the same but I'm getting an error: "Module ' ../node_modules/@angular/material/material ' has no exported member MatTableDataSource . Is there anything I'm missing? Here's the package.json versions: "dependencies": { "@angular/animations": "^4.4.6", "@angular/cdk": "^2.0.0-beta.12", "@angular/common": "^4.2.4", "@angular/compiler": "^4.2.4", "@angular/core": "^4.2.4", "

How to make HTTP GET+POST request in Protractor

核能气质少年 提交于 2019-12-03 07:39:43
I am facing problem to send HTTP get request in Protractor. Actually, I need to check data in DB after perform some action in UI. It will be very helpful if I will be able to do it using JQuery, but I am not able to find a way how to use JQuery inside Protractor. Need Help !! Actually, we did try to use the Node.js lib as shown below, but facing problems in it. var http = require('http'); var json_data; http.get('SiteUrl', function(response) { var bodyString = ''; response.setEncoding('utf8'); response.on("data", function(chunk) { bodyString += chunk; }); response.on('end', function() { json

How to use jasmine to test an async function that takes a long time to respond?

心已入冬 提交于 2019-12-03 07:32:15
I'm using a function to fetch data from webapi. Basicly using $.ajax . I'm now testing it with waits() like this: describe('xxxxxxxxxxxxxxxxxxxxx', function () { var r; it('fetchFilter', function () { runs(function () { model.fetch(opts) .done(function(data) { r = data; }); }); waits(2000); runs(function () { expect(r[0].gender).toBeDefined(); }); }); }); The problem is: It's not guaranteed that waits(2000) will do the job well. Due to various reasons(network connections, algorithm efficiency of the api it self, etc.), I may have to waits(5000) or more, or for some models waits(500) is enough.

How can i test a AngularJS provider?

让人想犯罪 __ 提交于 2019-12-03 07:32:13
问题 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. 回答1: It's actually a lot simpler than it would at first seem to test a

Checking object equality in Jasmine

家住魔仙堡 提交于 2019-12-03 07:20:50
问题 Jasmine has built-in matchers toBe and toEqual . If I have an object like this: function Money(amount, currency){ this.amount = amount; this.currency = currency; this.sum = function (money){ return new Money(200, "USD"); } } and try to compare new Money(200, "USD") and the result of sum, these built-in matchers will not work as expected. I have managed to implement a work-around based on a custom equals method and custom matcher, but it just seems to much work. What is the standard way to

testing ember.js apps with jasmine

早过忘川 提交于 2019-12-03 07:11:44
问题 Does anyone know of any resources, examples or tutorials about testing ember.js apps ? How do you test views ? There does not seem to be any extensive examples / information on this. 回答1: I can't propose an example how you can achieve that, but I have found a project which extensively uses Jasmine for their test: you should take a look at the ember-resource project on GitHub. It uses Jasmine for their tests, which are located in spec/javascripts. The project also has a Rakefile and

Mocking modules in Node.js for unit testing

岁酱吖の 提交于 2019-12-03 07:03:19
问题 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