question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

withActions: CustomEvent detail missing

See original GitHub issue

Is your feature request related to a problem? Please describe. I had originally filed this as a bug report, but belatedly decided that it’s technically a feature request.

Basically, though, when I am building a WebComponent which generates a CustomEvent, I want to be sure that the CustomEvent is being generated properly.

Describe the solution you’d like withActions (from @storybook/addon-actions) should include in the log the detail property of an event it receives if the event is a CustomEvent (or there should be some other documented way for stories to listen for a CustomEvent and see its detail property in the log).

Describe alternatives you’ve considered (using html from lit element and render from lit html), I render: <button type="button" @click="${this.publishtest}">publish</button>

And, I add a publish method on that class:

publishtest() {
  this.dispatchEvent(new CustomEvent('pubexample', {detail: {a: 1, b: 2}, bubbles: true}));
}

And, in my stories I include: .addDecorator(withActions('pubexample'))

I click the button, and something representing my example event shows up in the console log, but the detail property appears to be missing (or at least is not accessible from the console.log in chrome).

Are you able to assist bring the feature to reality? I don’t know - I’ll try implementing this tomorrow and submit a pull request if I can make this work.

Additional context Possibly relevant is that the logged message has a data property which has an args property which is an array of one element which is seems to be my CustomEvent but the only visible property of that item is {isTrusted: false}. Meanwhile, if I save that CustomEvent globally, and display it in the log, I see something completely different (with about 16 properties, but Object.keys() on that object only gets me isTrusted and _constructor-name_ – so a part of the issue here is simply that chrome doesn’t let me see inherited properties in the context of the logged message, perhaps because the CustomEvent is deeply nested in the message).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:25 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
dutschercommented, Dec 16, 2020

@shilman an update for telesync is necessary https://github.com/storybookjs/telejson/blob/master/src/index.ts#L209 in this line we need


const constructorName = value.constructor.name;
Object.assign(value, {
  '_constructor-name_': constructorName,
  ...(constructorName.toLowerCase().includes('event') ? {
    eventData: JSON.parse(JSON.stringify(value, Object.keys(value.constructor.prototype))),
    details: value.detail,
  } : {}),
});

then we get the result as my snapshots above shown.

cheers

Read more comments on GitHub >

github_iconTop Results From Across the Web

CustomEvent.detail - Web APIs - MDN Web Docs
The read-only detail property of the CustomEvent interface returns any data passed when initializing the event.
Read more >
Javascript CustomEvent detail not getting passed
The event works and fires correctly, but the 'detail' object that I'm passing it is not available. Here's the code I'm using to...
Read more >
Docs • Svelte
Component events created with createEventDispatcher create a CustomEvent. These events do not bubble. The detail argument corresponds to the CustomEvent.detail ...
Read more >
Custom events in JavaScript: A complete guide
We'll go over the following in detail: How to create a custom event in JavaScript; Using the event constructor; Using the CustomEvent ......
Read more >
How to check the CustomEvent detail in a Jest test for an LWC?
This Jest Test Patterns and Mock Dependencies includes the answer: return Promise.resolve().then(() => { expect(handler).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found