jasmine

angular karma unit test using $httpBackend + $resource without bootstrapping with module

折月煮酒 提交于 2019-12-12 02:29:05
问题 Requirements Angular based REST client component Must interact between a private API and services Karma/Jasmine test does not bootstrap app module Current dilemma We do not want to bootstrap the entire application for unit tests (using module() or angular.mock.module()). It does not seem sustainable for an enterprise level application, even though Angular's component registration is a useful feature. All the examples I have found do it this way, however per our current business objectives, I

Atom 'spec' files not being tested

不想你离开。 提交于 2019-12-12 02:15:25
问题 Following up from my previous question, here, I am trying to get 'spec' files registered by Atom, which I have succeeded in, however now, no matter how many describe and it 's I do, it doesn't do anything when I test it. I use the command, apm test , and all I get is: [655:0527/083825:WARNING:resource_bundle.cc(305)] locale_file_path.empty() for locale English [655:0527/083825:ERROR:file_io.cc(30)] read: expected 40, observed 0 [659:0527/083825:WARNING:resource_bundle.cc(305)] locale_file

Angular 2 Unit Testing: Injecting Typemoq objects

假装没事ソ 提交于 2019-12-12 02:09:28
问题 I'm implementing a unit test for a Service in Angular 2 (RC4) in Typescript. The service to test ("Calculation") uses a lot of other components ("Bausparen"), which on their part use components ("BausparenInput"). All components are declared @Injectable(). I tried to mock the depending components like Bausparen using Typemoq and injecting them before running the tests. Anyway, it doesn't work: FAILED TESTS: Calculation Service × should return empty array when fromYear > toYear PhantomJS 2.1.1

How can I load a module with RequireJS for testing in a testing framework like Jasmine?

╄→尐↘猪︶ㄣ 提交于 2019-12-12 01:54:10
问题 I am new to JavaScript and try to test functions defined in a RequireJS Module. That means i have some code like this: define([...], function(...){ var ModuleName = Base.extend({ init: function(){ //some code }; }); } Now I want to test the function init(). I load the object from my spec.js, this works: describe("ModuleName", function(){ var mod = require(['../js/app/ModuleName.js'], function(ModuleName) {}); it("exists", function(){ expect(mod).toBeDefined(); }); }); This passes well. But

Testing $resource without mock

橙三吉。 提交于 2019-12-12 01:39:11
问题 I'm trying to test the asynchronous $resource service by Angular. Firstly note that I don't want to mock $resource, I actually want to get the results and test them. So basically my getCountries method just uses Angular's $resource to return an array of countries. Method getCountries(): any { var countries = this.$resource( this.apiEndpoint.baseUrl, { 'get': { method: 'GET', isArray: false } }); return countries; } In my spec I'm having trouble with where to run Jasmine's done() method.

How to test a JavaScript Image onerror callback in Jasmine?

て烟熏妆下的殇ゞ 提交于 2019-12-12 01:37:39
问题 I'm having an url loader that I can pass in an URL and it will use a dynamically created JavaScript new Image() and its src property to load the url. In case an error happens, I'm logging it to the console. The simplified JavaScript code would be: var UrlLoader = function(url) { this.url = url; this.image = new Image(); this.image.onerror = function() { console.log("image error"); }; this.load = function() { this.image.src = this.url; }; } My question now is, how I can test that console.log(

Protractor - works well on localhost but remote throws Timeout - Async callback was not invoked within timeout specified

≡放荡痞女 提交于 2019-12-12 01:14:01
问题 When I execute protractor protractor.conf.js --baseUrl=http://localhost:4200/ , it works well - fills data, validates elements, etc. When I try to test exactly the same website via remote URL protractor protractor.conf.js --baseUrl=http://the-same-website.com/ , it opens up in browser, logins and all necessary parts are loaded like in localhost but Protractor/Jasmine does not fill/click/validate anything and I get timeout after specified time: - Error: Timeout - Async callback was not invoked

Angular and ES6: Karma Testing with SystemJS

雨燕双飞 提交于 2019-12-12 00:25:32
问题 Afternoon all, I have a MEAN stack app that I am developing tests for. The Angular code is written using ES6 so I have been trying to configure Karma and SystemJS with Babel as the transpiler to run my tests. Currently, when I karma start karma.conf.js the browser fires up, hangs—as in I cannot click debug or anything else—, and then the browser closes with the console error: Uncaught TypeError: Cannot set property 'mock' of undefined. The last line before this is DEBUG [web-server]: serving

Angular-Jasmine, loading json

早过忘川 提交于 2019-12-11 23:33:43
问题 I am trying to load json from local folder and then feed it into function to test it. Here is what I am trying to do: it('should be able to use treatExpResultJSON() function to treat incoming JSON', function() { require(['./jsonSampleData.json'], function(json){ expect(dirService.treatExpResultJSON(json)).not.toBeNull(); expect(dirService.treatExpResultJSON(json)).not.toBeUndefined(); console.log(json); console.log("Testing json passed!"); }); }); expect is not working inside the require

custom matcher makes jasmine to hang

…衆ロ難τιáo~ 提交于 2019-12-11 23:25:00
问题 Trying to call this custom matcher in jasmine testing tool but I got this error: TypeError: matcherCompare is undefined var result = matcherCompare.apply(null, args); jasmine.js (line 1192) My matcher: /* * Extends jasmine expectations by defining new matchers */ beforeEach(function () { jasmine.addMatchers({ toEqualArray: function(){ var s = typeof this.actual, result = false; if (s === 'object'){ if (this.actual){ if (Object.prototype.toString.call(this.actual) === Object.prototype.toString