Skip to content

Commit 24871d1

Browse files
committed
add test against function nested rule memory leak
1 parent 7dfbfdb commit 24871d1

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

packages/jss-plugin-rule-value-function/src/plugin-nested.test.js

+33-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import expect from 'expect.js'
22
import {stripIndent} from 'common-tags'
33
import {create} from 'jss'
4+
import {getCss, getStyle, removeWhitespace, resetSheets} from '../../../tests/utils'
45
import pluginNested from '../../jss-plugin-nested'
56
import pluginFunction from '.'
67

7-
const settings = {createGenerateId: () => (rule) => `${rule.key}-id`}
8+
const settings = {createGenerateId: () => rule => `${rule.key}-id`}
89

910
describe('jss-plugin-rule-value-function: plugin-nested', () => {
1011
let jss
@@ -20,7 +21,7 @@ describe('jss-plugin-rule-value-function: plugin-nested', () => {
2021
sheet = jss
2122
.createStyleSheet(
2223
{
23-
a: (data) => ({
24+
a: data => ({
2425
color: data.color,
2526
'@media all': {
2627
color: 'green'
@@ -60,7 +61,7 @@ describe('jss-plugin-rule-value-function: plugin-nested', () => {
6061
{
6162
a: {
6263
color: 'red',
63-
'@media all': (data) => ({
64+
'@media all': data => ({
6465
color: data.color
6566
})
6667
}
@@ -92,6 +93,8 @@ describe('jss-plugin-rule-value-function: plugin-nested', () => {
9293
describe('nested selector inside of a fn rule', () => {
9394
let sheet
9495

96+
beforeEach(resetSheets())
97+
9598
beforeEach(() => {
9699
sheet = jss
97100
.createStyleSheet(
@@ -123,6 +126,33 @@ describe('jss-plugin-rule-value-function: plugin-nested', () => {
123126
}
124127
`)
125128
})
129+
130+
describe('issue #1360: no memory leak', () => {
131+
beforeEach(() => {
132+
sheet.update({color: 'green'})
133+
sheet.update({color: 'red'})
134+
sheet.update({color: 'yellow'})
135+
sheet.update({color: 'green'})
136+
})
137+
138+
const expectedCSS = stripIndent`
139+
.a-id {
140+
color: red;
141+
}
142+
.a-id a {
143+
color: green;
144+
}
145+
`
146+
it('sheet', () => {
147+
expect(sheet.toString()).to.be(expectedCSS)
148+
})
149+
150+
it('DOM', () => {
151+
const style = getStyle()
152+
const css = getCss(style)
153+
expect(css).to.be(removeWhitespace(expectedCSS))
154+
})
155+
})
126156
})
127157

128158
describe('nested selector as a fn rule', () => {

0 commit comments

Comments
 (0)