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

fix memory leak in dynamic nested rule #1563

Merged
merged 16 commits into from
Oct 16, 2021
Merged
Prev Previous commit
Next Next commit
add tests for multiple updates with function-nested
  • Loading branch information
seiyab committed Oct 10, 2021
commit ee85e7a2fb084e3cd17f3959a80828500c4aaa37
Original file line number Diff line number Diff line change
@@ -221,14 +221,15 @@ describe('jss-plugin-rule-value-function: plugin-nested', () => {
{link: true}
)
.attach()

sheet.update({color: 'green'})
})

afterEach(() => {
sheet.detach()
})

it('should return correct .toString()', () => {
sheet.update({color: 'green'})
it('should return correct .toString() on first update', () => {
expect(sheet.toString()).to.be(stripIndent`
.a-id {
color: red;
@@ -238,6 +239,68 @@ describe('jss-plugin-rule-value-function: plugin-nested', () => {
}
`)
})

it('should return correct .toString() on second update', () => {
sheet.update({color: 'blue'})

expect(sheet.toString()).to.be(stripIndent`
.a-id {
color: red;
}
.a-id a {
color: blue;
}
`)
})
})

describe('nested identical selector as a fn rule', () => {
let sheet

beforeEach(() => {
sheet = jss
.createStyleSheet(
{
a: {
color: 'red',
'&': ({width}) => ({
width
})
}
},
{link: true}
)
.attach()

sheet.update({width: '10px'})
})

afterEach(() => {
sheet.detach()
})

it('should return correct .toString() on first update', () => {
expect(sheet.toString()).to.be(stripIndent`
.a-id {
color: red;
}
.a-id {
width: 10px;
}
`)
})

it('should return correct .toString() on second update', () => {
sheet.update({width: '100px'})
expect(sheet.toString()).to.be(stripIndent`
.a-id {
color: red;
}
.a-id {
width: 100px;
}
`)
})
})

describe('deeply nested selector as a fn value', () => {
@@ -256,22 +319,23 @@ describe('jss-plugin-rule-value-function: plugin-nested', () => {
c: {
'&$a': {
'& $b': {
margin: () => '10px'
margin: ({margin}) => margin
}
}
}
},
{link: true}
)
.attach()

sheet.update({margin: '10px'})
})

afterEach(() => {
sheet.detach()
})

it('should return correct .toString()', () => {
sheet.update()
it('should return correct .toString() on first update', () => {
expect(sheet.toString()).to.be(stripIndent`
.a-id {
padding: 5px;
@@ -286,5 +350,23 @@ describe('jss-plugin-rule-value-function: plugin-nested', () => {
}
`)
})

it('should return correct .toString() on update', () => {
sheet.update({margin: '99px'})

expect(sheet.toString()).to.be(stripIndent`
.a-id {
padding: 5px;
}
.b-id {
background: blue;
}
.c-id {}
.c-id.a-id {}
.c-id.a-id .b-id {
margin: 99px;
}
`)
})
})
})