Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for accidental replace in v10.8.1 #1571

Merged
merged 2 commits into from
Oct 26, 2021

Conversation

seiyab
Copy link
Member

@seiyab seiyab commented Oct 23, 2021

Corresponding Issue(s):

Issue: #1565

What Would You Like to Add/Fix?

This commit itself doesn't add any features / fix any problems

Todo

  • Add test(s) that verify the modified behavior
  • Add documentation if it changes public API

Expectations on Changes

Test will fail unless #1565 is fixed

Changelog

@seiyab seiyab requested a review from kof as a code owner October 23, 2021 02:49
@kof
Copy link
Member

kof commented Oct 26, 2021

Verified, tests fail here, but succeed on master, merging, thanks!

@kof kof merged commit 6399dc5 into cssinjs:master Oct 26, 2021
import {renderToString} from 'react-dom/server'
import expect from 'expect.js'
import {stripIndent} from 'common-tags'
import createCommonBaseTests from '../test-utils/createCommonBaseTests'
import {getCss, getStyle, removeWhitespace, resetSheets} from '../../../tests/utils'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh didn't notice it before merging, something.test.js are supposed to be unit tests only, so no dom dependency

@seiyab can you please move dom/cssom specific stuff to react-jss/tests?

Do we actually need DOM-based assertions for this test or would be registry.toString() already enough?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OH I just checked, we don't do DOM based assertions in react-jss at all, because we wanted to keep it react specific without going low-level.

So if you want to assert CSSOM, we need we would need a low level test for this behavior in jss core, if that doesn't exist already.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kof

can you please move dom/cssom specific stuff to react-jss/tests?

OK, I will.

Do we actually need DOM-based assertions for this test or would be registry.toString() already enough?

If I remember correctly, we need it.
registry.toString() rendered correct string, but not in DOM.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If lower level behavior is not new to jss, so all we test is react-jss logic - we don't need to assert CSSOM here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right.
I would move it to jss core.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw

Tests that focus on DomRenderer are unnatural because it doesn't fully work without StyleSheet

We use stylesheet for the most tests

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing DomRenderer.replaceRule via StyleSheet and Rule is impossible when setSelector works.

if setSelector was an issue in react-jss, then we just need to log what react-jss passes to jss and do the same thing in jss

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact the ideal functional jss test looks to me like this:

createStyleSheet(styles).attach()
expect(getCss()).to.be(....)

Copy link
Member Author

@seiyab seiyab Oct 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cause of #1565 (comment) is DomRenderer.refCssRule with index < cssRule.length - 1 , that exists from more than a year ago.
However, jss <= 10.8.0 rarely goes the path. Because DomRenderer.replaceRule is only for some old browsers.
So it is difficult to test it at v10.8.0 or v10.8.2.
On the other hand, v10.8.1 waked the bug. It utilized DomRenderer.replaceRule in StyleSheet.replaceRule and replaced rule by different rule, that caused #1565 (comment) .
This react-jss test checks "rerendering component should not delete rule by update of another rule".
v10.8.0 passes the test because v10.8.0 just adds more and more rules on update rather than replace.
v10.8.1 fails the test because v10.8.1 accidentally replace rules by other rules in DOM though it replaces rules in RuleList correctly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to write tests in PR that also adds replaceRule, so that we can write test for DomRenderer.refCssRule and DomRenderer.replaceRule.
Please correct me if I'm going wrong way.

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.

2 participants