Cannot read property '_ownerDocument' of undefined while mocking ref - react-test-renderer

I am using createMockNode from react-test-renderer and have mocked out the style to prevent undefined errors.
let createNodeMock = (element) => {
if (element.type === 'input') {
return {
style: {"color":"red"},
};
}
return null;
}
This has prevented the "undefined" error on style, but now I get this
error :
TypeError: Cannot read property '_ownerDocument' of undefined
at unstable_runWithPriority (A:\frontend\node_modules\scheduler\cjs\scheduler.development.js:643:12) TypeError: Cannot read property '_ownerDocument' of undefined
at exports.matchesDontThrow (A:\frontend\node_modules\jest-environment-jsdom\node_modules\jsdom\lib\jsdom\living\helpers\selectors.js:8:27)
at setPropertiesFromRule (A:\frontend\node_modules\jest-environment-jsdom\node_modules\jsdom\lib\jsdom\browser\Window.js:536:72)
at forEach.call.rule (A:\frontend\node_modules\jest-environment-jsdom\node_modules\jsdom\lib\jsdom\browser\Window.js:552:11)
(BTW, I am testing react-bootstrap-typeahead inside my component.)
Am I correctly creating the mock object for the input?

Related

Is there a way to get rid of the Runaway Promise warning when using react-query

I am using react-query useQuery as follows:
const { isLoading, error, data } = useQuery('repoData', () => {
return fetch('https://api.github.com/repos/tannerlinsley/react-query').then(res =>
res.json()
)
}
)
It generates the following warning:
Warning: a promise was created in a handler at webpack-internal:///./node_modules/react-query/es/core/retryer.js:68:50 but was not returned from it.
Is there anyway to remove it.
I am using Typescript

Mapbox getSource return object returns undefined values

I am calling the getSource method inside a load event like so:
map.on('load', () => {
map.addSource("country-boundary-source", {
type: "vector",
url: "mapbox://mapbox.country-boundaries-v1"
});
const source = map.getSource("country-boundary-source");
console.log("Source:", source);
})
In the output, the object has fields such as vectorLayers and vectorLayerIds. However when I call these values using source.vectorLayers I get an undefined value returned to me. I'm not really sure why this would be happening, since it is being outputted.

Cannot read property 'sPath' of undefined error while performing .read() method

I am confused with the error I get while trying to do .read() method of the odata model.
Here is my model definition:
var oModel = new sap.ui.model.odata.ODataModel("/destination/sap/opu/odata/sap/ODataServer");
this.getView().setModel(oModel, "odata");
Here is the relevant method:
_read: function(aFilters) {
var oModel = this.getView().getModel("odata");
console.log("oModel",oModel);
oModel.read("/myEntitySet", {
filters: aFilters,
success: function(oData) {
console.log("oData",oData);
},
error: function(oError) {
console.log("oError",oError);
}
});
}
The model is defined and is displayed in console.
In the line where the .read() method is, I get the following error:
Uncaught TypeError: Cannot read property 'sPath' of undefined
I have never seen such behavior before. What do I do wrong?
I had an error in my aFilters array. Well,the problem was that aFilters wasn't array at all. After fixing this issue, the .read() method worked fine.

Protractor 'toContain' error

This is my expect:
expect(mandatoryFields[index].getAttribute('class')).toContain('error');
This is the error in console:
Expected['formControl ng-pristine ng-untouched ng-valid ng-empty ng-valid-maxlength error'] to contain 'error'.
Eventhough the class contains ERROR class name, protractor is still throwing error. What could be reason? Any help!!!
Instead of toContain try using toMatch. toContain is used to check whether the required value is present in an array or not. whereas toMatch uses regex for validating the text present in any value.
You could try adding a custom matcher in your beforeEach(), then calling expect(mandatoryFields[index]).toHaveClass('error');
jasmine.addMatchers([
toHaveClass: function () {
return {
compare: function (element, className) {
return {
pass: element.getAttribute('class').then(function (classes) {
return classes.split(' ').indexOf(className) !== -1||classes.split(' ').indexOf(className+"\n") !== -1;
}),
message: "Expected elemenet to have class: "+className
}
},
negativeCompare: function(element, className){
return {
pass: element.getAttribute('class').then(function (classes) {
return classes.split(' ').indexOf(className) !== -1||classes.split(' ').indexOf(className+"\n") === -1;
}),
message: "Expected element not to have class: " + className
}
}
}
}
]);

Why when I click on the update button error TypeError: r is undefined happen?

The error in firefox browser as follows: TypeError: r is undefined
This is the chrome browser:
Uncaught TypeError: Cannot read property 'data' of undefined
I also did a video for a better understanding.
The error occurs when I changed the values ​​in a field
jsfiddle code
youtube video
button code update
save: function (e) {
var that = this;
$.ajax({
url: '/api/apdevice',
type: e.model.id == null ? 'POST' : 'PUT',
contentType: 'application/json',
data: JSON.stringify(e.model),
success: function (data) {
alert('yes');
that.refresh();
},
error: function (data) {
alert('no');
that.cancelRow();
}
});
}
The reason for this is because your datasource's update method is being called. It has not been set which gives you the TypeError.
You can do one of two things.
Set the update method of your datasource to contain the logic contained in your save function. You'll need to set update as a function in order to be able to control the method dynamically (POST/PUT). You should remove the ajax code from the save event at this point.
Set the update method to a dummy function and handle it as part of the save event instead.
Here's an example of approach #2.
var dataSource = new kendo.data.DataSource({
..
update: function(e) { return true; }
..
});
Keep the save event function as is.
Note that I'm getting an Uncaught SyntaxError: Unexpected number error. I believe this is originating from the LastClientsCount property.
Fiddle: http://jsfiddle.net/mSRUe/23/