Comments (6)
Hey, sorry for late response...
you can define methods from the descriptor file (add "methods" section):
export default {
component,
methods: {
someName: () => showroom.component.doSomething(arg1, arg2, ...),
someOtherName: () => showroom.component.doSomethingElse(),
...
}
}
If you want to trigger via puppeteer simply await showroom.trigger('someName')
Prepare your actions in the descriptor and they are also accessible via the UI.
Hope this helps.
from showroom.
Thank you for the reply. Unfortunately, it doesn't seem to be working.
export default {
component: 'an-element',
alias: '<an-element>',
path: '/.build/an-element.mjs',
autoAttributes: true,
autoProperties: true,
properties: {
'clickCount': 0
},
events: ['clickcountchanged'],
functions: {
click: () => showroom.component.click()
},
methods: {
isReady: () => showroom.component.isReady()
},
innerHTML: `
Click Me
`
};
it('should be ready', async () => {
const isReady = await showroom.trigger('isReady');
const ready = await showroom.getProperty('ready');
console.log('ready', isReady, ready);
assert.equal(ready, true);
});
The isReady
method on the element returns a promise once first rendering is done. From manual testing it is working correctly. I need to be able to invoke it in my Mocha tests. This is the error I am getting.
Error: Evaluation failed: TypeError: this.customControlForm.triggers[fnName] is not a function
at HTMLElement.trigger (http://127.0.0.1:3001/component-dashboard.js:26:46)
at puppeteer_evaluation_script:3:17
from showroom.
Also, what do the autoProperties
and autoAttributes
keys do? I have been trying to figure out how to use this by just looking at the examples.
from showroom.
- Is it supposed to be methods and not functions?
- I think the problem may be with your trigger function? I don't see that it returns anything?
async trigger (fnName) {
await this.page.evaluate((fnName) => {
// @ts-ignore
dashboard.trigger(fnName);
}, fnName);
}
and then the trigger on your dashboard doesn't return the value either...
trigger (fnName) {
if (fnName && this.customControlForm) {
this.customControlForm.triggers[fnName]();
}
}
from showroom.
Sorry, I am new to using Puppeteer. After digging through your code more, studying the Puppeteer API, finding the page reference, and then experimenting directly with page.evaluate
, it seems there are some issues with Puppeteer with regard to invoking methods on elements. Despite being able to manually invoke a method that returns a promise through the browser, I was unable to invoke it correctly in Puppeteer.
from showroom.
This is correct, it is not meant for calculations. You can, however run the function and get the results using puppeteer.
it('should do something', async () => {
const result = await page.evaluate((param) => {
return showroom.component.computeSomething(param);
}, someValueForParameter);
console.log(result);
}
The enclosed function will be executed in the browser, and the result is serialised by puppeteer.
I think that adding returned value using showroom's wrapper is worth a feature.
from showroom.
Related Issues (10)
- Feature Request: findAll HOT 9
- Bug: showroom.utils.trigger is fluffy HOT 10
- Need help with understanding Showroom HOT 8
- Render Container / Wrapper Overlay HOT 1
- FF<66 Does not support `import()` HOT 1
- Missing dependency HOT 1
- The site doesn't work HOT 1
- Using internal properties editor strips down properties with function values HOT 1
- Documentation issues
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from showroom.