Whenever i try to mock the apex method in test case i am getting "Cannot read properties of undefined (reading 'then') " error - jestjs

if i place the " isOptimizationV2Enabled.mockResolvedValue(false);" inside before each it works as expected, but i want to assign the different value for each test case.
I tried several methods but facing same error

Related

TypeError: Cannot read property 'map' of undefined when liking

I'm creating a site allowing me to create posts, as well as to comment on them.
I have a problem when I like or dislike a comment.
I get the following error:
TypeError: Cannot read property 'map' of undefined
I have already implemented the like/dislike feature for posts and have not encountered any problems.
I'm open to any proposal to move forward.
my github project : https://github.com/AlexisAndre34/mernswiftproject
thanks!
You are trying to map over something that's undefined
check your data exists first
data && data.length > 0 && data.map(...

Cloud Firestore node.js invalid use of type "object" as a Firestore argument

My question is about why I can't seem to pass data into a Firestore database. I'm running code on node.js trying to parse data coming from my Firebase Firestore database and then return information back to the database. Retrieval of the information works fine, but an error message that I cannot escape for the life of me keeps appearing when trying to pass data back to the database.
if(message.type = "0") {
console.log(0)
db.collection("outbox").doc("messageID").set({message: "test message"})
}
On trying to process the last line of code, the following error message appears:
Error: Argument "data" is not a valid Firestore document. Invalid use of type "object" as a Firestore argument.
My database is structured as outbox/messageID/message. Message holds a string value and I'm using the admin SDK so write issues aren't a problem. I'm doing something wrong with passing the object along to Firebase but I just can't figure it out. This is my first time working with Cloud Firestore and node.js but I've done small-scale projects in HTML/JS before.
It looks like an internal error with the way firestore checks if a value is an array.
I have the same issue trying a simple
db.collection('Test').add({ foo: 'bar' })
Which leads to
Error: Value for argument "data" is not a valid Firestore document. Invalid use of type "object" as a Firestore argument
After digging into firebase source code i found they check if an object is an object, based on this test :
Object.getPrototypeOf(input) === Object.prototype
Which is false in some environments for some unknwon reasons (In my case: Node v10.15.3 CLI)
As a workaround if you temporary needs to have this works, you may edit your node module source code in this file : node_modules/#google-cloud/firestore/build/src/serializer.js
Change the isPlainObject function to :
function isPlainObject(input) {
return util_1.isObject(input);
}

Key not being recognized in JSON

I have following JSON that i am trying to parse.
{"id":1,"colour":"blue","count(colour)":1}
It is a result of what i have returned from my sqlite3 select staement. I am doing a count(colours), which is being returned as the key in the JSON.
Then when i attempt to reference the value using .count(colour), my node app fails giving me an error that colour is not defined. Note, that referencing .id works just fine.
Has anybody ran into this issue before or can provide any help?
If your JSON is in some variable, myjson, and you access it directly with myjson.count(colours), you get the error because it's trying to execute a function in your object.
It works as you expect if you access via string like this: myjson["count(colour)"].

my nodejs error width Cannot read property data of undefined

my nodejs service always output this error : Cannot read property data of undefined, not only get data from other services ,but also query the db ,so please give me some suggestions,thanks;
If you look at the entire error that you quoted as "Cannot read property data of undefined" then you'll see that it includes the file name and line number. In that line you will see something like x.data and this error means that the x is undefined. If you add a console.log or other logging to that line and you'll try to print the x (or whatever name it is in your case) then you'll see that it is indeed undefined just before you get the error, contrary to what you described here.

OpenLayers 3: "Unable to get property 'leaf' of undefined or null reference."

Using Open layers 3.7.0.
I have layer with features. I remove one, build a new similar one, add the new one and I get error message
"Unable to get property 'leaf' of undefined or null reference."
I have searched for what could cause that but search don't give any result.
Some more from the same error (I used v3.8.2 here but got exactly the same:
at rbush.prototype._chooseSubtree (http://openlayers.org/en/v3.8.2/build/ol-debug.js:70778:13)
at rbush.prototype._insert (http://openlayers.org/en/v3.8.2/build/ol-debug.js:70815:9)
at rbush.prototype.insert (http://openlayers.org/en/v3.8.2/build/ol-debug.js:70623:19)
at ol.structs.RBush.prototype.insert (http://openlayers.org/en/v3.8.2/build/ol-debug.js:71178:3)
at ol.source.Vector.prototype.addFeatureInternal (http://openlayers.org/en/v3.8.2/build/ol-debug.js:71589:7)
at ol.source.Vector.prototype.addFeature (http://openlayers.org/en/v3.8.2/build/ol-debug.js:71566:3)
Progress
Where we build the feature we have a projection.
var lineString = new ol.geom.LineString(coordinates);
lineString.transform("EPSG:4326", "EPSG:3857");
var feature = new ol.Feature(lineString);
(...)
If we comment/remove
//lineString.transform("EPSG:4326", "EPSG:3857");
Then there is no bug. By the way that's an hint, not a solution as the features are then not located where they should be.
Solution found
I do not think that this is a perfect soluton but I solved the problem regarding or application by saving the LineStrings in memory instead of re-creating it.
Then I still recreate the Feature from existing LineString.
I got the same error on console and I solved this testing if the features had a valid geometry(coordinates), so I discard the inclusion of the invalid features on the layer source.

Resources