What's causing this Jasmine Http Observable error? - json

I'm running a unit test that makes a simple http call
karma.config.js, test.ts, tsconfig.js are all virgin boilerplate ng CLI 5.2.3, node, webpack and ts all latest versions. karma-webpack not used
The httpclient get call generates this error but only when run as a specified test in karma/jasmine/webpack:
TypeError: this.handler.handle is not a function at MergeMapSubscriber.WEBPACK_IMPORTED_MODULE_2_rxjs_operator_concatMap.a.call [as project] (:9876/_karma_webpack_/webpack:/C:/Users/sauna/Documents/adev/UK/node_modules/#angular/common/esm2015/http.js:1174)
at MergeMapSubscriber._tryNext (:9876/_karma_webpack_/webpack:/C:/Users/sauna/Documents/adev/UK/node_modules/rxjs/_esm2015/operators/m
This is the test specification that makes the http call as part of an an integration suite:
httpClientInstance.get('myAPIurlReturningAJsonObj').subscribe(
(data) => {
testID = data.MessageText;
},
(error) => {
console.log(error);
}
);
..expectation is any string to testID
the error is something with the Observable presented by ng not being handled by Jasmine
ping me I need to present more information, thx

Answering my own question may be wrong, new to StackOverflow - I hope I've found the answer. I believe that this error's a threading/socket issue. Accessing a Jasmine http request as a unit test doesn't seem possible without using Spy. I've solved the immediate problem using Protractor

Related

invoke web3.eth.get_transaction() but it shows "has no attribute 'get_transaction'"

I'm new on web3. Recently I'm trying to decode some logs on Ethereum according to this article. But when I try to use code like receipt=web3.eth.get_transaction(transaction_hash). It keeps showing me that module 'web3.eth' has no attribute 'get_transaction'.
But apparently, my computer has this file. And, doesn't this kind of statement mean "I'm trying to call a function in web3.eth"? Why is it regarded as "calling an attribute"?
Here are my codes:
import json
import requests
from web3 import Web3
w3=Web3(Web3.HTTPProvider(infura_project))
receipt=web3.eth.get_transcation(transaction Hash) //always show error "web3.eth has no attribute get_transaction"
log=receipt["logs"][2]
smart_contract=log["address"]
mykey="MY API Key of Etherscan"
adi_endpoint=f"https://api.etherscan.io/api?module=contract&action=getabi&address={smart_contract} & apikey={mykey}" //problem (2)
abi=json.load(requests.get(adi_endpoint).text)
//decode info
And if I directly put my API key of Etherscan at the end of line 10, pycharm will mark an error in there. So I enclose the API key in double quotes and assign it to the variable "mykey". Honestly, I don't think this will work. How to solve this problem?
Well, it's working for my code :
from web3 import Web3
web3 = Web3(Web3.HTTPProvider('https://bsc-dataseed.binance.org/'))
result = web3.eth.get_transaction('0x690ffe41506456a3936aa2d4dd05de6601f1fbe7eb3fe23c2bcc4d17714ea617')
print(result)
Make Sure Below Things
1: The web3 library is up to date
2: You don't have any file in your system named web3.py or Web3.py or something like this.

Jasmine is not define error after using jest-circus

Would like to use jest.retryTimes() & for that I have installed jest-circus however while running test getting jasmine not define error .
To achieve above I have added testRunner: "jest-circus/runner" in jest.config.js
I am using puppeteer framework with jest test runner.
Exact error :
Test suite failed to run
ReferenceError: jasmine is not defined
at registerAllureReporter (node_modules/jest-allure/dist/setup.js:46:5) at Object. (node_modules/jest-allure/dist/setup.js:49:1)
Please check my answer to the similar question regarding undefined jasmine with jest-circus runner being used: https://stackoverflow.com/a/66073466/1445507

feathers-blob error dauria can no read property startsWith

I just started using feathers-blob for uploading files from a angular4 client using dropzone.
I followed the example but made an explicit service for the upload not tu blur up the app.js.
It compiles without error, but on execution i receive the following error, even i do NOT use multipart portion:
Info: error:
system/file-upload - Method: create: Cannot read property 'startsWith'
of undefined error: TypeError: Cannot read property 'startsWith' of
undefined
at Dauria.parseDataURI (/projects/esaas-2/esaas-server-basic/node_modules/feathers-blob/node_modules/dauria/dauria.js:27:17)
at Object.create (/projects/esaas-2/esaas-server-basic/node_modules/feathers-blob/lib/index.js:87:52)
at /projects/esaas-2/esaas-server-basic/node_modules/feathers-hooks/lib/hooks.js:101:31
at /projects/esaas-2/esaas-server-basic/node_modules/feathers-hooks/lib/hooks.js:85:16
I also made sure to use the same versions of feathers-blob and dauria and multer as in the sample and not the newer ones from the npm. Result is the same.
What am i doing wrong? Any help appreciated. Thanks
If you look into dauria's code you'll see where the problem comes from:
Dauria.prototype.parseDataURI = function(dataURI){
if(!( dataURI.startsWith('data:') )) throw new Error(
this.errors.MISSING_PREFIX
);
Which means that somehow the value that you pass to the caller dauria.parseDataURI(yourDataVariable) - the yourDataVariable value does not start with 'data:'.
I made a test on Node and I had the same error while trying to upload an image. I solved it by adding the string "data:image/jpeg;base64" followed by the 64 encoded image.

The noticeError method was not found. while using Coldbox and NewRelic for Error tracking

I'm just using NewRelic error trapping for my coldbox application. From OnException method, I'm just sending the error struct to log the error.
My code in onexception method
public function onException(event,rc,prc){
NewRelic.logError( prc.exception.getExceptionStruct());
}
The logerror() method resides in NewRelic.cfc and contains the following code
public boolean function logError(
required struct exception
) {
var cause = arguments.exception;
var params = {
error_id = createUUID(),
type: arguments.exception.type,
message: arguments.exception.message
};
writeDump(this.newRelic);
this.newRelic.noticeError(cause, params);abort;
return true;
}
So while error, I'm gettig the following error.
The noticeError method was not found.
You can see that, the noticeError() method is there in the object, but it is overloaded with arguments.
I'm using the same code for NewRelic error trapping in another coldfusion project without any frameworks.
Calling error.cfm through Cferror tag, and the code in error.cfm as follows
<cfset Application.newRelic.logError( variables.error )>
And in NewRelic.cfc, the logerror() method contains the same code as in the coldbox application. But it is logging errors in NewRelic without any issues.
This is the method I need to notice errors and log it in NewRelic.
noticeError(java.lang.Throwable, java.util.Map)
So I just thought to get the classname of the first argument Cause through the following code from both applications within logError() in NewRelic.cfc, to get the difference.
writeDump(cause.getClass().getName());
I'm getting
coldfusion.runtime.ExceptionScope for Coldbox application
and
coldfusion.runtime.UndefinedVariableException for normal coldfusion application
The cause argument is not throwable from coldbox application. So how to get the original error struct from coldbox application? and make it throwable to fix the noticeError method was not found issue.
The change in the underlying class happens when ColdBox duplicates the error object with CFML's duplicate() method. I doubt that ColdFusion behavior is documented anywhere, but I don't see an easy way to get around it right now other than creating your own instance of a java.langException and populating it with the details of the original error.
If you want to modify the ColdBox core code, this happens here:
https://github.com/ColdBox/coldbox-platform/blob/master/system/web/context/ExceptionBean.cfc#L43
I have entered this ticket for the ColdBox framework for us to review if we can stop duplicating the error object in future versions of the framework.
https://ortussolutions.atlassian.net/browse/COLDBOX-476
Update: Adam Cameron pointed out this ticket in the Adobe bug tracker that details this behavior in the engine. It was closed as "neverFix".
https://bugbase.adobe.com/index.cfm?event=bug&id=3976478

Observable Command and Unit tests with Rx RTM

I have ported my code to the RTM version of both WinRT and Rx. I use ReactiveUI in my ViewModels. Before porting the code my unit tests were running without problem but now I got a strange behavior.
Here the test:
var sut = new MyViewModel();
myViewModel.MyCommand.Execute(null) //ReactiveAsyncCommand
Assert.AreEqaul(0, sut.Collection.Count)
If I debug the test step by step, the assertion is not failing, but using the test runner it's failing...
The Collection asserted is modified by a method subscribing to the command:
MyCommand.RegisterAsyncTask(_ => DoWork())
.ObserveOn(SynchronizationContext.Current)
.Subscribe(MethodModifyingCollection);
The code was working before moving it to the RTM. I tried also to remove the ObserveOn and add an await Task.Delay() before the Assert without success.
Steven's got the rightish answer, but there are a few RxUI specific things missing. This is definitely related to scheduling in a test runner, but the reason is that the WinRT version of ReactiveUI can't detect properly whether it's in a test runner at the moment.
The dumb workaround for now is to set this at the top of all your tests:
RxApp.DeferredScheduler = Scheduler.CurrentThread;
Do not use the TestScheduler for every test, it's overkill and actually isn't compatible with certain kinds of testing. TestScheduler is good for tests where you're simulating time passing.
Your problem is that MSTest unit tests have a default SynchronizationContext. So ObserveOn and ReactiveAsyncCommand will marshal to the thread pool instead of to the WPF context. This causes a race condition.
Your first and best option is the Rx TestScheduler.
Another option is to await some completion signal (and ensure your test method is async Task, not async void).
Otherwise, if you just need a SynchronizationContext, you can use AsyncContext from my AsyncEx library to execute the tests within your own SynchronizationContext.
Finally, if you have any code that directly uses Dispatcher instead of SynchronizationContext, you can use WpfContext from the Async CTP download.