Jasmine spy "expect(xxx).notToHaveBeenCalled() - javascript

With great thanks to those that so swiftly rescued me. The essence of the problem was that I failed to realize I should be looking in documentation for "matchers", and looking in "expect" was not going to solve my problem.
I'm working with Jasmine 3.0 (and very new to it!) and trying to verify that a spy sees zero calls to a target under particular conditions. I thought I might use the count() behavior for this, but I'm struggling to work out what syntax I should use.
I've tried
spyOn(target, 'action').and.callThrough();
target.triggeringAction();
expect(target.action).count().toBe(0);
But Jasmine reports TypeError: expect(...).count is not a function.
I don't see any expect(...).toNotHaveBeenCalled() and I'm not sure where to look next.

You could use expect(target.action).toHaveBeenCalledTimes(0);

This could work as well expect(target.action).not.toHaveBeenCalled();

Related

Unable to execute karate script() method

I am trying to migrate one of selenium test to karate, while doing this I am using script() method defined in documentation which is used in karate for evaluating the given string as JavaScript within the browser but I am getting this
driver.executeScript("sauce:job-result=passed");
Also Sharing my feature file which getting failed:
Also Even I tried calling below statement in my script but still getting the same error
* script("console.log('hello world')")
I am using testImplementation("com.intuit.karate:karate-core:1.2.0.RC1") version with gatling
First - try version 1.2.0.RC6 that has some fixes for the console.log() issue.
I also must say that sauce:job-result=passed does not look like valid JavaScript to me. Please take some time to read the docs: https://github.com/karatelabs/karate/tree/master/karate-core#karate-vs-the-browser
If still stuck, follow this process. That is the only way to replicate and for us to determine what fixes we need to make (if any): https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue
See this answer for ideas on how to troubleshoot things at your end: https://stackoverflow.com/a/71952132/143475

How to remove warnings from lastValue in SparkAR

In a SparkAR script, I use star.transform.z.lastValue to get the actual number. I want to do some math with the numbers, not with ScalarSignals (observable values). Now by doing so, I get lots of warnings:
This API is deprecated, please update to the newest SDK version.
Please use pinLastValue() instead to receive a ConstSignal as a replacement for lastValue
I don't see what ConstSignal is or how to extract the value from it, since the documentation seems to be lacking:
https://sparkar.facebook.com/ar-studio/search/ConstSignal
I tried doing figure out what kind of fields/functions it has with reflection, but reflection doesn't seem to work in SparkAR, and I don't have code completion on it either. So I have no idea how to resolve this.
Everything works fine when I'm just using lastValue, but I'd love to have a clean console.
Note: I am using Spark AR Studio v96
Use star.transform.z.pinLastValue() to instead.

angular ngRoute breaks when using base tag

Can anyone tell me what is wrong with my code? I put up a simple webpage to show you: http://plnkr.co/edit/TkADpfgchYVdvNTqRPFT?p=preview
I'm using base tag with a sub dir along with html5mode and the beta version
I don't think you're really doing anything wrong. I think its a bug in the new release candidate. You're not really even doing anything special. Its just in your $locationProvider.html5Mode(true); call. That function calls angular's beginsWith function, which calls .indexOf on the url string, which is apparently undefined. I would suggest creating a bug for it on angular's github page. You can do that here. I would simply post this issue and the link to your plunker and they should be able to handle it.
That's precisely why they ask us to test the rc's. Good find. I'm not actually using HTML5Mode, so I hadn't found this particular bug yet.
You are trying to call a method of an undefined variable. You should probably add a check such as:
if (typeof variable ==="undefined")

How to stub javascript dependencies (jquery) in jasmine?

I have some legacy code on my hands which was written with/relies upon the following stack:
jquery 1.8.1
jquery lazyload 1.8.0
d3 v2
Before I change anything in the code, I figured I'd write tests for it, so I can make nothing brakes :).
I chose the jasmine test framework because I'm familiar with rspec
I'm running into some issues, because the code I want to write tests for relies on jquery to define some "constants" e.g:
var WIDTH = $(document).width();
I guess there is no way around stubbing.
Should I include jquery in jasmine and try to spec the document?
Or not include jquery in jasmine and stub $?
I fear I might be going down the wrong direction and would much appreciate some guidance (code snippets much appreciated). Thanks for helping a noob out!
I would include jQuery and mock the functions that it calls. In your example, I would do.
spyOn($.fn, 'width').andReturn(300); //Return a value that you expect to be used
Jasmine spies have a property calls that is an array of all the calls and one thing that I have done is examine the calls entries and you can check the calling object. That being a jQuery object it has the property selector which you can expect to be equal to document
expect($.fn.width.calls[0].object.selector).toEqual(document);
Though remember you are trying to test the expected behavior of the code, not that each step of the code is completed as it is written. Trying to test that certain lines exists will prevent you from easily refactoring.

Javascript HTML5 FileAPI: Uncaught ReferenceError: utils is not defined

I can't find this anywhere, and no one else has this problem that I know of.
I'm using the code straight off http://www.w3.org/TR/FileAPI/ and I can't get it to work at all.
Here's the jsfiddle I've been using to test it out http://jsfiddle.net/4k5xa/
The example is not a complete, working example. It calls hypothetical library functions. You will need to implement them or not use them.

Categories

Resources