I want to use a javascript sdk inside of my flutter app (the pi network sdk only supports javascript), I am building this app for pi network hackathone
I tried to do some thing like that but it didn't :
class Test2 extends StatelessWidget {
const Test2({super.key});
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: TextButton(
child: Text("click"),
onPressed: () {
js.context.callMethod("eval", [
"""require(['https://sdk.minepi.com/pi-sdk.js'], function (Pi) {
Pi.init({ version: '2.0' });
// Authenticate the user and request payments
const scopes = ['payments'];
function onIncompletePaymentFound(payment) { /* ... */ }
Pi.authenticate(scopes, onIncompletePaymentFound)
.then(function (auth) {
console.log(`Hi there! You're ready to make payments!`);
})
.catch(function (error) {
console.error(error);
});
});
"""
]);
}),
));
}
}
but I am getting this error:
The following LegacyJavaScriptObject object was thrown while handling a gesture:
Error: Mismatched anonymous define() module: function() { return CanvasKitInit; }
http://requirejs.org/docs/errors.html#mismatch
When the exception was thrown, this was the stack:
require.js 168:17 makeError
require.js 1254:36 intakeDefines
require.js 1446:21 localRequire
require.js 1797:24 requirejs
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/js_patch.dart 144:53 eval
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/js_patch.dart 144:53 callMethod
packages/remenberit/test.dart 20:24 <fn>
packages/flutter/src/material/ink_well.dart 1096:21 handleTap
packages/flutter/src/gestures/recognizer.dart 253:24 invokeCallback
packages/flutter/src/gestures/tap.dart 627:11 handleTapUp
packages/flutter/src/gestures/tap.dart 306:5 [_checkUp]
packages/flutter/src/gestures/tap.dart 239:7 handlePrimaryPointer
packages/flutter/src/gestures/recognizer.dart 615:9 handleEvent
packages/flutter/src/gestures/pointer_router.dart 98:12 [_dispatch]
packages/flutter/src/gestures/pointer_router.dart 143:9 <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/linked_hash_map.dart 21:13 forEach
packages/flutter/src/gestures/pointer_router.dart 141:17 [_dispatchEventToRoutes]
packages/flutter/src/gestures/pointer_router.dart 127:7 route
packages/flutter/src/gestures/binding.dart 460:19 handleEvent
Related
I'm trying to use fixtures to hold data for different tests, specifically user credentials. This is an example of the code. I'm getting 'Cannot read properties of undefined (reading 'data')'. I tried to google search , I found Cypress fixtures - Cannot read properties of undefined (reading 'data')
I used closure variable technique as reccomended in that post , yet I got reference error of unable to reference data.Please help me.I know cypress.config can be used but I want to keep that for global configs
Json(credentials.json):
{
"username":"*****",
"password":"*****"
}
Code:
import { LoginPage } from "./pageobject/login_page"
describe('Test Scenario', () => {
before(function () {
cy
.fixture('credentials').then(function (data) {
this.data = data
})
})
it('Simple login', () => {
cy.visit(Cypress.env('url'))
var loginpage = new LoginPage()
loginpage.EnterUsername(this.data.username)
loginpage.clickonSubmit()
loginpage.EnterPassword(this.data.password)
loginpage.clickonSubmit()
Cypress
.on('uncaught:exception', (err, runnable) => {
return false;
});
cy.
wait(10000)
cy.
get('span[id="user"]').should('have.text', this.data.username , 'User Login Unsuccessfully')
});
});
There's a few things need adjusting
use function () {} syntax in the it() block
use beforeEach() and alias to load the fixture, because data on this can be cleared (especially after login)
move uncaught:exception catcher to the top of the block
don't cy.wait(), instead add timeout to next command
.should() only has two parameters in this case, so use .and() to test the 2nd text
import { LoginPage } from './pageobject/login_page';
describe('Test Scenario', () => {
beforeEach(function () {
cy.fixture('credentials').as('data')
})
it('Simple login', function() {
Cypress.on('uncaught:exception', (err, runnable) => {
return false;
});
cy.visit(Cypress.env('url'));
var loginpage = new LoginPage();
loginpage.EnterUsername(this.data.username);
loginpage.clickonSubmit();
loginpage.EnterPassword(this.data.password);
loginpage.clickonSubmit();
cy.get('span[id="user"]', {timout:10_000})
.should('have.text', this.data.username)
.and('have.text', 'User Login Unsuccessfully')
})
})
I suspect it's because you are using an arrow function instead of a regular function, you cannot access the this object with an arrow function.
Cypress docs
If you store and access the fixture data using this test context
object, make sure to use function () { ... } callbacks. Otherwise the
test engine will NOT have this pointing at the test context.
change it to this:
it('Simple login', function() {
...
});
I am experiencing a very strange issue. I have developed an app via [useDapp][1] and in the app I have many view calls. It works perfectly when I connect my account (which is the Deployer/Creator), but produces 32000 error for all the calls when I connect another Metamask account. Also transactions work perfectly, but view functions revert...
The network is Binance Smartchain Testnet.
Here is one of the smart contracts
https://testnet.bscscan.com/address/0x6ae13e6B49Ab13d6D51060008d586aF48DE59b97#code
The chain definition
export const BSCTestnetChain: Chain = {
chainId: 97,
chainName: 'BSC Testnet',
isTestChain: true,
isLocalChain: false,
multicallAddress: '0xae11C5B5f29A6a25e955F0CB8ddCc416f522AF5C',
getExplorerAddressLink: (address: string) =>
`https://testnet.bscscan.com/address/${address}`,
getExplorerTransactionLink: (transactionHash: string) =>
`https://testnet.bscscan.com/tx/${transactionHash}`,
// Optional parameters:
rpcUrl: 'https://data-seed-prebsc-2-s3.binance.org:8545/',
blockExplorerUrl: 'https://testnet.bscscan.io',
nativeCurrency: {
name: 'BNB',
symbol: 'BNB',
decimals: 18,
},
};
The example of a call:
export function useX11Ballance(address: string | Falsy) {
const { value, error } =
useCall({
contract: x11Contract, // instance of called contract
method: 'balanceOf', // Method to be called
args: [address], // Method arguments - address to be checked for balance
}) ?? {};
if (error) {
console.error(error.message);
return undefined;
}
return value?.[0];
}
Example of an error:
react_devtools_backend.js:4026 processing response error (body="{\"jsonrpc\":\"2.0\",\"id\":96,\"error\":{\"code\":-32000,\"message\":\"execution reverted\"}}\n", error={"code":-32000}, requestBody="{\"method\":\"eth_call\",\"params\":[{\"to\":\"0xae11c5b5f29a6a25e955f0cb8ddcc416f522af5c\",\"data\":\"0x252dba4200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000260000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000044000000000000000000000000000000000000000000000000000000000000004e000000000000000000000000000000000000000000000000000000000000005a00000000000000000000000000000000000000000000000000000000000000660000000000000000000000000f555f02220d22cea9aefbe569181de30256d2f18000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000248f03e382000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ced4de7c1a8f19a5666fcb3609668992f0670983000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000243f2c00fc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ced4de7c1a8f19a5666fcb3609668992f06709830000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000002416353e0c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ced4de7c1a8f19a5666fcb3609668992f0670983000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000242f380b350000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006ae13e6b49ab13d6d51060008d586af48de59b970000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000002470a08231000000000000000000000000ca04e3ff4bfc69c02f6dae8b21ff2c045312941a0000000000000000000000000000000000000000000000000000000000000000000000000000000052dda844620da41a61459448cb0c15ee4bae9cd50000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000002470a08231000000000000000000000000ca04e3ff4bfc69c02f6dae8b21ff2c045312941a00000000000000000000000000000000000000000000000000000000000000000000000000000000f555f02220d22cea9aefbe569181de30256d2f18000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000442f745c59000000000000000000000000ca04e3ff4bfc69c02f6dae8b21ff2c045312941a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ced4de7c1a8f19a5666fcb3609668992f0670983000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000445a4988c50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ca04e3ff4bfc69c02f6dae8b21ff2c045312941a000000000000000000000000000000000000000000000000000000000000000000000000000000006ae13e6b49ab13d6d51060008d586af48de59b9700000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000044dd62ed3e000000000000000000000000ca04e3ff4bfc69c02f6dae8b21ff2c045312941a000000000000000000000000ced4de7c1a8f19a5666fcb3609668992f067098300000000000000000000000000000000000000000000000000000000\"},\"0x14ca18e\"],\"id\":96,\"jsonrpc\":\"2.0\"}", requestMethod="POST", url="https://data-seed-prebsc-2-s3.binance.org:8545/", code=SERVER_ERROR, version=web/5.6.1)
at ContinueBlock (http://localhost:3000/static/js/bundle.js:7411:5)
at div
at div
at div
at PollPage (http://localhost:3000/static/js/bundle.js:12023:67)
at Routes (http://localhost:3000/static/js/bundle.js:94629:5)
at div
at App
at UIProvider (http://localhost:3000/static/js/bundle.js:12408:5)
at PoolProvider (http://localhost:3000/static/js/bundle.js:12289:5)
at Router (http://localhost:3000/static/js/bundle.js:94562:15)
at BrowserRouter (http://localhost:3000/static/js/bundle.js:93371:5)
at TransactionProvider (http://localhost:3000/static/js/bundle.js:42263:5)
at NotificationsProvider (http://localhost:3000/static/js/bundle.js:42078:5)
at MultiChainStateProvider (http://localhost:3000/static/js/bundle.js:41325:5)
at LocalMulticallProvider (http://localhost:3000/static/js/bundle.js:40505:5)
at BlockNumbersProvider (http://localhost:3000/static/js/bundle.js:40723:5)
at BlockNumberProvider (http://localhost:3000/static/js/bundle.js:40654:5)
at NetworkProvider (http://localhost:3000/static/js/bundle.js:41666:5)
at ReadonlyNetworksProvider (http://localhost:3000/static/js/bundle.js:41919:5)
at WindowProvider (http://localhost:3000/static/js/bundle.js:42488:5)
at DAppProviderWithConfig (http://localhost:3000/static/js/bundle.js:40428:5)
at ConfigProvider (http://localhost:3000/static/js/bundle.js:41486:5)
at DAppProvider (http://localhost:3000/static/js/bundle.js:40398:5)
Would be grateful for any kind of help or hint.
[1]: https://usedapp.io
I have a service (no view) that depends on DialogService from aurelia-dialog, and uses that for opening a dialog. I want to test my service. While doing that I got the following error on dialogService.open(...).
Error: DialogRenderer must implement getDialogContainer().
at Renderer.getDialogContainer (webpack-internal:///./node_modules/aurelia-dialog/dist/native-modules/renderer.js:14:15)
at DialogService.open (webpack-internal:///./node_modules/aurelia-dialog/dist/native-modules/dialog-service.js:139:106) ...
I got the idea that I need to load the plugin aurelia-dialog before running any of test cases. To this end, I tried the following.
import { bootstrap } from "aurelia-bootstrapper";
import { Aurelia, Container, PLATFORM } from "aurelia-framework";
describe("test specs", () => {
let container: Container;
beforeAll(async () => {
await bootstrap(async (aurelia: Aurelia) => {
aurelia.use
.standardConfiguration()
.developmentLogging()
.plugin(PLATFORM.moduleName("aurelia-dialog"), (config) => {
config.useDefaults();
config.settings.lock = true;
config.settings.centerHorizontalOnly = false;
config.settings.startingZIndex = 5;
config.settings.keyboard = true;
});
Container.instance = container = new Container();
aurelia.container = container;
await aurelia.start();
});
});
});
But than I got the following error on aurelia.start.
Error: Loader must implement loadAllModules(ids).
at Loader.loadAllModules (webpack-internal:///./node_modules/aurelia-loader/dist/native-modules/aurelia-loader.js:113:11)
at ViewEngine.importViewResources (webpack-internal:///./node_modules/aurelia-templating/dist/native-modules/aurelia-templating.js:3593:24)
at eval (webpack-internal:///aurelia-framework:646:23)
at <Jasmine>
at loadResources (webpack-internal:///aurelia-framework:637:7)
at eval (webpack-internal:///aurelia-framework:731:14)
at next (webpack-internal:///aurelia-framework:577:30)
at runTasks (webpack-internal:///aurelia-framework:583:10)
at eval (webpack-internal:///aurelia-framework:936:16)
at <Jasmine>
at eval (webpack-internal:///aurelia-framework:935:21)
at <Jasmine>
at FrameworkConfiguration.apply (webpack-internal:///aurelia-framework:919:42)
at Aurelia.start (webpack-internal:///aurelia-framework:463:37) ...
Thus, my question is how to correctly load the aurelia-dialog plugin in this scenario?
I have a page pages/login.js looks like:
function fillAndSubmitLogin(email, password) {
return this
.waitForElementVisible('#emailInput')
.setValue('#emailInput', email)
.setValue('#passwordInput', password)
.waitForElementVisible('#loginSubmitButton')
.click('#loginSubmitButton');
}
export default {
commands: [
fillAndSubmitLogin
],
elements: {
emailInput: 'input#email',
passwordInput: 'input[type=password]',
TFAInput: 'input#token',
loginSubmitButton: '.form-actions button.btn.btn-danger'
}
};
I have another page pages/hompage.js homepage.js attempts to include pages/login.js as a section
import login from "./login.js";
module.exports = {
url: 'http://localhost:2001',
sections: {
login: {
selector: 'div.login-wrapper',
...login
}
}
};
I then have a test case that attempts to login on the hompage section
'Homepage Users can login': (client) => {
const homepage = client.page.homepage();
homepage
.navigate()
.expect.section('#login').to.be.visible;
const login = homepage.section.login;
login
.fillAndSubmitLogin('user#test.com', 'password');
client.end();
}
This test then fails with the following error
TypeError: login.fillAndSubmitLogin is not a function
at Object.Homepage Users can login (/Users/kevzettler//frontend/test/nightwatch/specs/homepage.spec.js:32:6)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:182:7)
login.fillAndSubmitLogin is not a function
at Object.Homepage Users can login (/Users/kevzettler//frontend/test/nightwatch/specs/homepage.spec.js:32:6)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:182:7)
According to the Nightwatch docs, any commands that are exported in page objects should be plain JavaScript objects with a key being a command name and the value being a function. For example:
var googleCommands = {
submit: function() {
this.api.pause(1000);
return this.waitForElementVisible('#submitButton', 1000)
.click('#submitButton')
.waitForElementNotPresent('#submitButton');
}
};
module.exports = {
commands: [googleCommands],
elements: //...etc ...
// etc...
}
In this example, the module exports googleCommands, which is a command object which has a key (submit) and a corresponding function. I believe you should refactor your code as follows:
function fillAndSubmitLogin = {
fillAndSubmitLogin: function(email, password) {
return this
.waitForElementVisible('#emailInput')
.setValue('#emailInput', email)
.setValue('#passwordInput', password)
.waitForElementVisible('#loginSubmitButton')
.click('#loginSubmitButton');
}
};
Of course, you don't have to make the command name the same in both places (as the example shows (googleCommands/submit). This allows you to expose a variety of functions in one command. Hope that answers the question!
I use default Aurelia's sceleton-esnext updated to last version .
I added this line to App (
Example from doc. Customizing the Navigation Pipeline)
config.addPipelineStep('authorize', AuthorizeStep);
After this I catch error running 'gulp test'
Chrome 52.0.2743 (Linux 0.0.0) the App module contains a router property FAILED
TypeError: config.addPipelineStep is not a function
Test
it('contains a router property', () => {
expect(sut.router).toBeDefined();
});
Test is going well without line.
I just came across this issue. To fix, you just need to add an empty method into your RouterStub:
class RouterStub {
configure(handler) {
handler(this);
}
map(routes) {
this.routes = routes;
}
addPipelineStep(stepName, stepClass) {
}
}
then in your test:
describe('the App module', () => {
var app;
var mockedRouter;
beforeEach(() => {
mockedRouter = new RouterStub();
app = new App();
app.configureRouter(mockedRouter, mockedRouter);
});
it('contains a router property', () => {
expect(app.router).toBeDefined();
});
});
If you're trying to test the pipeline step you'll need to mock the router itself and test the actual logic, but if you just want your tests to run (i.e. be defined, check the router title etc), this will work.