Declaring slimLoadingBarService with let, you are constraining its scope to the beforeEach callback scope. Declare it with var, or better, declare it after the proper describe() block and set its content within beforeEach callback function:

describe("some describe statement" , function(){
    let slimLoadingBarService = null;

    beforeEach( () => {
        slimLoadingBarService=new SlimLoadingBarService();

    });

    it('should pass data to service', () => {
        spyOn(slimLoadingBarService,'start').and.callThrough();
       //testing code,if I remove the above service from my component, test runs fine
    });
});
Answer from Sergeon on Stack Overflow
🌐
GitHub
github.com › jasmine › jasmine › issues › 1149
How can I call a spy upon a function being exported through a module · Issue #1149 · jasmine/jasmine
July 13, 2016 - controller = require('controller.js') beforeEach(() => { spyOn(controller, 'foo').and.callFake((args, action) => { // return something }); }) it('testing foo function', (done) => { server.inject(opts, cb) function cb(res){ expect(controller.foo).toHaveBeenCalled(); } })
Author   jrcastillo
Discussions

angular - <spyOn> : could not find an object to spy upon - Stack Overflow
The first 3 tests are passing, the last one returns Error: : could not find an object to spy upon for changeTitle() More on stackoverflow.com
🌐 stackoverflow.com
Error: “component cannot define both template and templateUrl”
Repost from StackOverflow. Hope that's ok. I have some karma/phantomjs tests that used to work but now give me this error for every component even though the components do not in fact define both template and templateU… More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
0
May 19, 2017
angular - could not find an object to spy upon for navigateBackToLanding - Stack Overflow
While running my test, I'm getting this error could not find an object to spy upon for navigateBackToLanding. I've searched and done all the steps which was mention, but still i'm getting the erro... More on stackoverflow.com
🌐 stackoverflow.com
December 28, 2018
Jasmine failure: Error: <spyOn> : could not find an object to spy upon for postSkillforMember()
I am trying to test a method which does not return nothing. The method calls a service to perform a Http POST. I have mocked my service and set it as a parameter within SpyOn. The second parameter ... More on stackoverflow.com
🌐 stackoverflow.com
March 16, 2022
🌐
GitHub
github.com › vitest-dev › vitest › issues › 1344
v0.12.7: regression on vi.spyOn(Storage.prototype) #1344
May 20, 2022 - Error: spyOn could not find an object to spy upon ❯ <anonymous> test/basic.test.ts:12:5 10| 11| test('JSON', () => { 12| vi.spyOn(Storage.prototype, 'setItem'); Maybe this is an intended change, but I did not see something relevant in the changelog · https://stackblitz.com/edit/vitest-dev-vitest-sfvqc9?file=test/basic.test.ts,package.json,vite.config.ts&initialPath=__vitest__ Revert to 0.12.6 in package.json to see the error go away.
Published   May 20, 2022
Author   cexbrayat
🌐
SmartBear Community
community.smartbear.com › smartbear community › testcomplete › testcomplete questions
How to work when Object Spy doesn't find object | SmartBear Community
Hi Just starting out with TC. I'm a little unsure what the best practice is when I can't find the element with object spy. I have multiple items that I...
🌐
Google Groups
groups.google.com › g › jasmine-js › c › 5VQyX4JT_NY
How to test a new object and its methods in AngularJS service
I'm not able to add a spy to this new ResourceExceptionHandler object. I want to check if setException and setExceptionMessage methods were correctly called.
🌐
freeCodeCamp
forum.freecodecamp.org › t › error-component-cannot-define-both-template-and-templateurl › 117611
Error: “component cannot define both template and templateUrl” - The freeCodeCamp Forum
May 19, 2017 - Repost from StackOverflow. Hope that’s ok. I have some karma/phantomjs tests that used to work but now give me this error for every component even though the components do not in fact define both template and templateUrl. I don’t know whether it’s related but I am also getting many reports of this error: Error: : could not find an object to spy upon for find() Usage: spyOn( , ) in /Users/Dan/work/bernierebuttals/gba/node_modules/jasmine-core/lib/jasmine-core/jasmine...
🌐
GitHub
github.com › ike18t › ng-mocks › issues › 567
Testcases are failing after upgrading to 11.1+ · Issue #567 · help-me-mom/ng-mocks
May 18, 2021 - @Component: ___Component ✗ ngOnInit (82ms) SyntaxError: Unexpected identifier at <Jasmine> at JitEvaluator.evaluateCode (http://localhost:9876/_karma_webpack_/vendor.js:10798:20) at JitEvaluator.evaluateStatements (http://localhost:9876/_karma_webpack_/vendor.js:10768:21) at CompilerFacadeImpl.jitExpression (http://localhost:9876/_karma_webpack_/vendor.js:23362:39) Error: <spyOn> : could not find an object to spy upon for dispatch() Usage: spyOn(<object>, <methodName>) Error: <spyOn> : could not find an object to spy upon for dispatch() Usage: spyOn(<object>, <methodName>) at <Jasmine>
Find elsewhere
🌐
CopyProgramming
copyprogramming.com › howto › lt-spyon-could-not-find-an-object-to-spy-upon-for-login
Fixing "spyOn Could Not Find an Object to Spy Upon" for Login Testing in 2026 - Find an object to spy upon for login testing
December 8, 2025 - The "spyOn could not find an object to spy upon" error indicates that your testing framework cannot locate the function or method you're attempting to spy on within the provided object. This typically occurs when the object reference is undefined, the method doesn't exist on that object, or ...
🌐
Jasmine
jasmine.github.io › tutorials › spying_on_properties
Spying on Properties
Properties are more complicated than functions. In Jasmine, you can do anything with a property spy that you can do with a function spy, but you may need to use different syntax · Use spyOnProperty to create either a getter or setter spy
🌐
Blogger
unittesting1.blogspot.com › 2016 › 01 › error-spyon-could-not-find-object-to.html
unit testing: Error: spyOn could not find an object to spy upon for login()
describe('LoginController', function() { var scope, controller, userServiceMock, stateMock; beforeEach(module('user.controllers')); beforeEach(inject(function($rootScope, $controller) { scope = $rootScope.$new(); controller = $controller('LoginController',{ $scope: scope, $state: stateMock, UserService: userServiceMock }); })); beforeEach(function() { scope.doLoginAction = jasmine.createSpy('doLoginAction') }); describe('doLoginAction',function(){ it('should call odLoginAction method on LoginController', function(){ scope.doLoginAction(); }); it('should call login method on UserService', function(){ spyOn(userServiceMock,'login'); expect(userServiceMock.login).toHaveBeenCalledWith({username:'riju@gmail.com',password:'riju'}); }); }); });