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.

Add support for native class components

See original GitHub issue

I’m not seeing the expected behavior when binding the data-test-* ID within the Javascript file when using Native Classes

Taking your existing README.md example:

export default Ember.Component({
  comment: null,
  'data-test-comment-id': Ember.computed.readOnly('comment.id'),
});

Now convert to use native class syntax and observe that data-test-comment-id does not exist anymore.

Here is a very simple Ember Twiddle, inspect the DOM and you notice data-test-my-component attribute does not exist

https://ember-twiddle.com/7cf08b835afbcbba34f761bcf41930bc

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Turbo87commented, Nov 14, 2018

I don’t think that removes the need for a solution here

I personally don’t see the need here and won’t put time into it, but feel free to come up with a PR. The constraints are that it needs to behave quite close to the current solution and be entirely optimized out in prod builds.

0reactions
marcoowcommented, Dec 13, 2018

I’ll close this - essentially dataAttributeBindings (which ETS adds all data-test- attributes to automatically) is only necessary as currently component templates define inner HTML rather than outer so that dataAttributeBindings is the only way to get the data-test attributes on the component’s outer element. With the new component model where templates define the component’s outer HTML that is no longer necessary and the data-test attribute can be added to the component’s template directly.

In general, I’d advice against using a fixed data-test- attribute per component that is defined inside the component (be it the component’s .js or .hbs) as that makes the tests using the attribute depend on internals of the component and the fact that a specific component is used. What you should do instead is pass data-test- attributes into the component from the context in that the component is invoked - after all, you would usually want to use different data-test- attributes for different invokations of the same component:

<Button data-test-delete-user-button>Delete</Button>
…
<Button data-test-save-record-button>Save</Button>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Functional vs Class Components in React Native
In React Native, there are two main types of components that make up an application: functional components and class components.
Read more >
React Native: Functional and Class Components - Medium
Class components are JavaScript ES6 classes which are extended from a base class called React.Component. Class components are referred as Stateful as they...
Read more >
React Fundamentals - React Native
This short introduction to React can help you get started or get refreshed. ... Function Component; Class Component ...
Read more >
Component - React Docs
Component is the base class for the React components defined as JavaScript classes. Class components are still supported by React, but we don't...
Read more >
React Class Components - W3Schools
Create a Class Component​​ When creating a React component, the component's name must start with an upper case letter. The component has to...
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