Coder Social home page Coder Social logo

Call a method? about showroom HOT 6 CLOSED

eavichay avatar eavichay commented on July 19, 2024
Call a method?

from showroom.

Comments (6)

eavichay avatar eavichay commented on July 19, 2024

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.

 avatar commented on July 19, 2024

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.

 avatar commented on July 19, 2024

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.

 avatar commented on July 19, 2024
  • 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.

 avatar commented on July 19, 2024

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.

eavichay avatar eavichay commented on July 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.