spy

is there a way to monitor application in background & invisible from user

落花浮王杯 提交于 2019-12-12 06:48:05
问题 What I want to do is to create an application which can perform it's feature without user interaction. This shouldn't have any appicon at Applications page in Device. After installation user don't need to aware of application running in device. I tried with No Launcher Activity in a Demo Application but it is not running code of application and that's obvious. Is there a way to accomplish this task, Does this make any sense? 回答1: Yes it is possible, and it makes lot of sense. But it takes lot

How do I mock an exported typescript function in a jasmine test?

这一生的挚爱 提交于 2019-12-11 02:26:36
问题 I'm trying to mock a function exported from a typescript file in a Jasmine test. I expect the following to mock the imported foo and return the value 1 in the spec for bar. The mock appears to be uncalled, so I'm clearly missing something. How can I fix this example? demo.ts: export function foo(input: any): any { return 2; } export function bar(input: any): any { return foo(input) + 2; } demo.ts.spec: import * as demo from './demo'; describe('foo:', () => { it('returns 2', () => { const

Angularjs unit testing resolving promises

…衆ロ難τιáo~ 提交于 2019-12-07 21:24:55
问题 I'm probably doing this wrong but I can't figure out how to fix it. I want to test a controller that uses a resource (ngResource) and I want to use a Spy as a test double for the resource so it doesn't actually do the http call. In the code below I just want to test the search function in the controller. Controller: controllers = angular.module('app.controllers'); controllers.controller('landingCtrl', ['$scope', '$q', 'categoryResource', function ($scope, $q, categoryResource) { $scope.search

Injection an object though InjectMocks Spy

纵然是瞬间 提交于 2019-12-07 06:33:29
问题 I need to run series of unit tests over a class, which has a @Autowired Logger implementation. The base idea of realization was: @Mock Logger logger; @InjectMocks TestedClass tested; but i want to save the logging output functionality. Does Mockito lib allow to inject objects with @InjectMock? I'w seen examples of @Spy annotation, but when i tried to use it, i always got NullPointerException. I know that i can always directly use reflect, but the idea is to avoid such code. 回答1: Well. I'll

Angularjs unit testing resolving promises

蓝咒 提交于 2019-12-06 05:45:01
I'm probably doing this wrong but I can't figure out how to fix it. I want to test a controller that uses a resource (ngResource) and I want to use a Spy as a test double for the resource so it doesn't actually do the http call. In the code below I just want to test the search function in the controller. Controller: controllers = angular.module('app.controllers'); controllers.controller('landingCtrl', ['$scope', '$q', 'categoryResource', function ($scope, $q, categoryResource) { $scope.search = function (text) { console.log('searching for: ' + text); var deferred = $q.defer(); categoryResource

Trying to spy (Jasmine) on Array.prototype methods causes stack overflow

狂风中的少年 提交于 2019-12-05 08:06:42
This is pretty odd. Using the testem runner with jasmine2 and the following spec executes (though it correctly flags that there are no expectations): describe('Spying on array.prototype methods', function(){ it('should work this way', function(){ spyOn( Array.prototype, 'push' ).and.callThrough(); // expect(1).toBe(1); }); }); However, add an expect (any expect !) and it causes the stack to overflow with the following message in the testem console: RangeError: Maximum call stack size exceeded. at http://localhost:7357/testem/jasmine2.js, line 980 The html report page gets up to the spec and

How do you spy on AngularJS's $timeout with Jasmine?

て烟熏妆下的殇ゞ 提交于 2019-12-05 07:55:11
I am trying to spy on $timeout so that I can verify that it has not been called. Specifically, my production code (see below) calls $timeout as a function, not an object: $timeout(function() { ... }) and not $timeout.cancel() // for instance Jasmine, however, requires an object to be spied upon, like this: spyOn(someObject, '$timeout') I don't know what 'someObject' would be though. I am using Angular mocks, if that makes any difference. Edit: The relevant production code I'm trying to test looks like this: EventHandler.prototype._updateDurationInOneSecondOn = function (call) { var _this =

Mockito spy method not working

纵然是瞬间 提交于 2019-12-04 17:36:32
I'm in trouble with mockito.spy method. I'm recently arrived on a "old" project and my first task is to add mockito in it, and to do real unit test :) the project has many conception problems but its not the point here ;) I explain my problem: I have a class public class Tutu{ public Tutu(){ } } public class Toto{ public Toto(){ } public int executeToto(Tutu tutu){ //do some stuff return 5; } } public class Titi{ private Toto toto; public Titi(){ this.toto = new Toto(); } public void executeTiti(){ //do some stuff Tutu tutu = new Tutu(); int ret = this.toto.executeToto(tutu); //do some stuff }

How to spy on a default exported function with Jest?

笑着哭i 提交于 2019-12-04 17:18:43
问题 Suppose I have a simple file exporting a default function: // UniqueIdGenerator.js const uniqueIdGenerator = () => Math.random().toString(36).substring(2, 8); export default uniqueIdGenerator; Which I would use like this: import uniqueIdGenerator from './UniqueIdGenerator'; // ... uniqueIdGenerator(); I want to assert in my test that this method was called while keeping the original functionality. I'd do that with jest.spyOn however, it requires an object as well as a function name as

How to spy on a default exported function with Jest?

老子叫甜甜 提交于 2019-12-03 12:25:51
Suppose I have a simple file exporting a default function: // UniqueIdGenerator.js const uniqueIdGenerator = () => Math.random().toString(36).substring(2, 8); export default uniqueIdGenerator; Which I would use like this: import uniqueIdGenerator from './UniqueIdGenerator'; // ... uniqueIdGenerator(); I want to assert in my test that this method was called while keeping the original functionality. I'd do that with jest.spyOn however, it requires an object as well as a function name as parameters. How can do this in a clean way? There's a similar GitHub issue for jasmine for anyone interested.