I'm creating a spy with createSpyObj():
mockAccessResolverService = jasmine.createSpyObj('AccessResolverService', ['resolveAccessByEntitlements', 'resolveAccess']);
I use createSpyObj() because I need to configure it as a provider in my test bed.
mockAccessResolverService.resolveAccess.withArgs([DELETE_PERMISSION]).and.returnValue(Observable.of(false));
TypeError: mockAccessResolverService.resolveAccess.withArgs is not a function
mockAccessResolverService.resolveAccess.and.withArgs([DELETE_PERMISSION]).and.returnValue(Observable.of(false));
--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.
To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at https://groups.google.com/group/jasmine-js.
To view this discussion on the web visit https://groups.google.com/d/msgid/jasmine-js/afd3e27e-220d-4599-9187-6b74a2cf357d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
mockAccessResolverService.resolveAccess.and.withArgs(AUTH_PERMISSIONS.DELETE).and.returnValue(Observable.of(false));
TypeError: mockAccessResolverService.resolveAccess.and.withArgs is not a function
spyOn(someObj, 'func').withArgs(1, 2, 3).and.returnValue(42);
mockAccessResolverService.resolveAccess.withArgs(AUTH_PERMISSIONS.DELETE).and.returnValue(Observable.of(false));
TypeError: mockAccessResolverService.resolveAccess.withArgs is not a function
From Jasmine's perspective, what you want to do is change the behavior of the spy after creating it. (Spies default to the `stub` strategy). In order to do this you'll need to use the `.and` chaining property to get back to spy things. This might look like:
mockAccessResolverService.resolveAccess.and.withArgs([DELETE_PERMISSION]).and.returnValue(Observable.of(false));Hope this helps. Thanks for using Jasmine!
On Tue, May 14, 2019 at 10:48 AM <jason...@blackbaud.com> wrote:
--
I'm creating a spy with createSpyObj():
mockAccessResolverService = jasmine.createSpyObj('AccessResolverService', ['resolveAccessByEntitlements', 'resolveAccess']);I use createSpyObj() because I need to configure it as a provider in my test bed.In my tests I want to provide the behavior for when the mocked methods are called, but I want different behavior depending on how the methods are called. If I had used spyOn() I could use withArgs() but it doesn't seem possible with a spy created with createSpyObj():
mockAccessResolverService.resolveAccess.withArgs([DELETE_PERMISSION]).and.returnValue(Observable.of(false));TypeError: mockAccessResolverService.resolveAccess.withArgs is not a functionIs it possible to create a spy with createSpyObj() and return different values based on the passed arguments?
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmi...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.
To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at https://groups.google.com/group/jasmine-js.
To view this discussion on the web visit https://groups.google.com/d/msgid/jasmine-js/4c703440-0eb9-40f8-b4ac-d8673d000682%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/jasmine-js/CACxUgK2ijtoKA%2BeOEOAr8ft7CPxnLY0OAG%2B3AmieTd9T_TURYQ%40mail.gmail.com.