I built a project with AngularJs and made unit test with Karma and jasmine.
One of my controller in Angular project need to refer socket.io to transport data with server. And i wrote the unit test case for this controller. Ana add 'socket.io.js' file into 'karma.conf.js', When i tested it with karma, an error throw out:
Uncaught TypeError: Cannot read property 'transport' of undefined, this error throw in below statement in adapter.js in karma-jasmine node package:
var getCurrentTransport = function() {
// probably running in debug.html (there's no socket.io)
if (!window.parent.io) {
return null;
}
var location = window.parent.location;
return window.parent.io.sockets[location.protocol + '//' + location.host].transport.name;
};
i'm not quit understand what this code mean, i found that the window.parent.io.sockets is an empty object, so added another statement to return null so that it won't throw an error.
var location = window.parent.location;
if(!window.parent.io.sockets[location.protocol + '//' + location.host]){
return null;
}
return window.parent.io.sockets[location.protocol + '//' + location.host].transport.name;
i'm not sure whether this change is right? Anyone know how to fix this problem?
#Zacho add these statement before return... in your adapter.js .
if(!window.parent.io.sockets[location.protocol + '//' + location.host]){
return null;
}
these just hack method,Although I don't think this is a good solution, i didn't find why this problem occur.
Related
I'm having an issue in gRPC that's been driving me crazy. I have a .NET gRPC service that my ReactJS client is connecting to - this works fine. I'm subscribing to my stream, and I get data over the stream as expected. I'm having an issue deserializing "google.protobuf.Any" types that exist in my messages. The one I'm receiving looks like this:
message PointNotification {
KindsOfPointNotification Kind = 1;
google.protobuf.Any NotificationData = 2;
}
Inside of the ReactJS client I am doing the following:
useEffect(() => {
console.log("Subscribing to point stream");
var pointStream = client.subscribeToNotificationStream(new Empty(), {});
pointStream.on("data", (response) => {
switch (response.getKind())
{
case KindsOfPointNotification.KINDS_OF_POINT_NOTIFICATION_POINT_ADDED_OR_UPDATED:
const any = response.getNotificationdata();
console.log(any);
const bar = any.unpack(NotificationPointAddedOrUpdated.deserializeBinary, any.getTypeName());
console.log(bar);
break;
case KindsOfPointNotification.KINDS_OF_POINT_NOTIFICATION_POINT_REMOVED:
console.log("Point removed");
break;
}
});
The "any" variable looks right in the browser logs. The payload, and the typeName are correct. However when I go to unpack "any" I get the following error (screenshot):
TypeError in browser
Uncaught TypeError: deserialize is not a function
This is despite the fact that the generated _pb file has the following method:
/**
* Deserializes binary data (in protobuf wire format).
* #param {jspb.ByteSource} bytes The bytes to deserialize.
* #return {!proto.Point.NotificationPointAddedOrUpdated}
*/
proto.Point.NotificationPointAddedOrUpdated.deserializeBinary = function(bytes) {
var reader = new jspb.BinaryReader(bytes);
var msg = new proto.Point.NotificationPointAddedOrUpdated;
return proto.Point.NotificationPointAddedOrUpdated.deserializeBinaryFromReader(msg,
reader);
};
According to The documentation this is correct way to do it. What am I missing? Why am I getting a deserialize error?
Edit: I have one other thing to add. If I change the following line:
const bar = any.unpack(NotificationPointAddedOrUpdated.deserializeBinary, any.getTypeName());
To:
const bar = any.unpack(NotificationPointAddedOrUpdated.deserializeBinary(), any.getTypeName());
The error I get in the browser changes to:
Uncaught TypeError: _proto_pointdata_pb_js__WEBPACK_IMPORTED_MODULE_3___default(...).deserializeBinary is not a function
The following issue led me to the solution: https://github.com/protocolbuffers/protobuf/issues/5482
The previous dev was not encoding data in base64, and that was causing deserialize issues in JavaScript.
I get a very strange exception with AngularJS 1.5.9
[$rootScope:inprog] null already in progress
Here is the source code where this exception is thrown:
function beginPhase(phase) {
if ($rootScope.$$phase) {
throw $rootScopeMinErr('inprog', '{0} already in progress', $rootScope.$$phase);
}
$rootScope.$$phase = phase;
}
beginPhase() is called with "$apply" or "$digest".
My question is:
How is it possible to enter the "if" while $rootScope.$$phase is null?
Any help will be appreciated.
To answer your question $rootScope.$$phase can be set to "null" (string) which will result in this error being thrown.
I'm not sure how you were able to capture this message but Sentry reports that for me and I'm getting a ton of those exceptions from just a bunch of users.
So in order to reduce the spam I made a function which will remove the stack from the exception, and will clear the $rootScope.$$phase which will hopefully prevent a second occurrence:
function exceptionHandler(){
const error = Error;
const nullMessage = "[$rootScope:inprog] null already in progress";
function exception(message){
if(message.indexOf(nullMessage) === 0){
const $rootScope = exceptionHandler.$rootScope;
if($rootScope) $rootScope.$$phase = null;
const exception = new error(nullMessage);
exception.stack = "";
return exception;
}
return new error(message);
}
Error = exception;
}
exceptionHandler(); // If it's not run AngularJS will use the original Error constructor, the one we're decorating
And then in angular.run inject $rootScope and set it as a property of the function:
angular.run(["$rootScope", function($rootScope){
exceptionHandler.$rootScope = $rootScope;
}]);
My assumption was that an extension was setting $rootScope.$$phase to "null" but after installing the same extensions as one of my users the exception did not occur.
Star on GistHub
Does any one know why i get an illegal invocation error with this code? I think it is because I am trying to inject a profile image into the object that im getting - in the line addedCard.image = userInfo.image; but I dont know how to fix it. And because its part of a firebase listener its a continuous loop of errors and they keep adding up. This is the code that I have:
My service:
service.cardAdded = function(cb){
// if(target === "all"){
if($rootScope.validID){
prayersRef.orderByChild("group").equalTo($localStorage.seedUser.id).on('child_added', function(snapshot){
var val = snapshot.val();
cb.call(this, {
to: val.to,
from: val.from,
date: val.date,
assigned: val.assigned,
group: val.group,
passage: val.passage,
id: snapshot.key()
});
});
}
};
My controller:
myService.cardAdded(function(addedCard){
$scope.card.push(addedCard);
ProfileService.retrieveName(addedCard.assigned,function(userInfo) {
if (userInfo.image) {
addedCard.image = userInfo.image; //I think that this is causing the error
};
});
});
this is the error:
TypeError: Illegal invocation
at isArrayLike (angular.js:266)
at forEach (angular.js:322)
at copy (angular.js:832)
at copy (angular.js:798)
at copy (angular.js:838)
at copy (angular.js:798)
at copy (angular.js:820)
at copy (angular.js:790)
at copy (angular.js:838)
at copy (angular.js:798)
(anonymous function) # angular.js:11706
(anonymous function) # angular.js:8619
(anonymous function) # angular.js:16417
completeOutstandingRequest # angular.js:4940
(anonymous function) # angular.js:5328
Any help would be appreciated. Thank you
This guidance from the AngularJS might be useful:
Lower-level DOM manipulation from your JS code ... is no-no with AngularJS
and
If you stick to manipulating data model angular.copy will work just fine.
https://github.com/angular/angular.js/issues/8353
Your code is calling angular.copy implicitly (you can see that in your Chrome error) so make sure you are only copying you data model, not whole DOM elements.
Have you tried assigning only the elements that you need from the userInfo.image to addedCard.image, instead of copying the whole object, like this?
addCard.image = new Card(userInfo.image);
function AddCard(userImage) {
var obj = {
// Assign the needed attributes
};
return obj;
}
I'm using Breeze and Angular on client and NHibernate on server.For business logic reasons I need to know if some object has changes after it has been saved.For that reasons I'm calling
manager.hasChanges(['ArrayOfTypes']);
In case when object is loaded from db it works as expected(returns true/false),
but after object is saved through
manager.saveChanges(['ArrayOfTypes']);
I get this error:
TypeError: Cannot read property 'hasChanges' of undefined
The error gets thrown here in breeze.js file:
proto._hasChangesCore = function(entityTypes) {
entityTypes = checkEntityTypes(this, entityTypes);
var entityGroups = getEntityGroups(this, entityTypes);
return entityGroups.some(function (eg) {
return eg.hasChanges();
});
};
I'm expecting 32 entityGroups to return and there are indeed 32 elements in array, but 25 of them are undefined.For now I've made a temp fix which does not feel right at all:
proto._hasChangesCore = function(entityTypes) {
entityTypes = checkEntityTypes(this, entityTypes);
var entityGroups = getEntityGroups(this, entityTypes);
return entityGroups.some(function (eg) {
if (eg !== undefined) {
return eg.hasChanges();
}
else {
return false;
}
});
};
Is there a way to deal with problem in other way?
Thanks
This happens when the one or more of the entity types is not represented by an EntityGroup in the entity manager. But you should be able to pass in any type name and not have it blow up.
This is a bug in Breeze, which is finally fixed. The fix will be in the next release.
Ok, i've tryed everything here. I did installed msnodesql from
-https://github.com/Azure/node-sqlserver
and
-http://www.microsoft.com/en-us/download/details.aspx?id=29995
following every line of instruction on installation. build with node-gyp... everything.
Then when I do something like:
var conn_str = "Driver={SQL Server Native Client 11.0};Server={(local)\\SQLEXPRESS};Database={DBName};Trusted_Connection={Yes};";
var stmt = sqlserver.query(conn_str, "SELECT * from av.CLIENT");
stmt.on('meta', function (meta) { console.log("We've received the metadata"); });
stmt.on('row', function (idx) { console.log("We've started receiving a row"); });
stmt.on('column', function (idx, data, more) { console.log(idx + ":" + data); });
stmt.on('done', function () { console.log("All done!"); });
stmt.on('error', function (err) { console.log("We had an error :-( " + err); });
it throws me an error on node console:
[Error: [msnodesql] Invalid passed to function query. Type should be .]
What drives me crazy is that it should be something like:
[Error: [msnodesql] Invalid --SOMETHING-- passed to function query. Type should be --SOMETHING_ELSE--.]
right?
It doesn't even pass through the stmt.on('error', line
I've repeated the installation steps over and over, thinking that maybe there was an error in the building process, but nothing.!
I'm using Windows 8 x64 and node v-0.10 (I wonder if that driver is ment to be use ONLY with node v.0.8 <
I need help. pls.
I have not used node-sqlserver, but I have used tedious and it worked well. Give that a try, maybe you'll have better luck?
Ok. I just found out why it gives errors like Error: [msnodesql] Invalid passed to function query. Type should be .] .
If you happen to have a prototype over the Array object, it will throw this kind of errors. For example, I have a prototype function over the Array class called "indexOfObject".....
To be more specific, there's a file in msnodesql > lib > sql.js , in it there's a function called validateParameters.
In there, I changed this:
if ( typeof parameters[p].value != parameters[p].type )
for this:
if ( typeof parameters[p].value != parameters[p].type && parameters[p].name )
it may not be overthinked as a solution to all my problems, but at least everything works fine from there on.!