Skip to content

Conversation

@abradley2
Copy link

I was using bel + cssauron-html to do some component testing in a completely node environment. In this case, bel uses this module to create the document structure. However, the elements were being created with empty id and className attributes.

The id and className properties on elements need to be handled a bit uniquely (others too I think but for now this is what I'm running into)

In a browser environment:

var el = document.createElement('div')

el.setAttribute('class', 'my-class')

el.className // returns 'my-class'

The reverse is true as well

var el = document.createElement('div')

el.className = 'my-class'

el.getAttribute('class') // returns 'my-class'

But this isn't working the way it is currently set up. Since setAttribute('class') will not affect className, and changes to className will not the corresponding 'class' to attributes.

So two changes

  1. setAttribute now handles id and className in a way that will put them directly on the dom element in addition to adding them to _attributes object
  2. id and className use object-defined wrapped setters so setAttribute can be called behind the scenes whenever these properties are set via the . operator
  3. Add tests to ensure these now behave as they do in the browser

This accurately mimics dom elements' behavior, so cssauron-html can work with bel in node from some pretty awesome testing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant