-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: corrects behavior of style removal (#3261)
* fix style removal behavior * adding tests * limit exports from package root Co-authored-by: Rob Eisenberg <EisenbergEffect@users.noreply.github.com>
- Loading branch information
1 parent
f772fa0
commit e37b7ab
Showing
3 changed files
with
47 additions
and
5 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
packages/web-components/fast-element/src/__test__/styles.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { expect } from "chai"; | ||
import { AdoptedStyleSheetsStyles, StyleTarget } from "../styles"; | ||
|
||
describe("AdoptedStyleSheetsStyles", () => { | ||
context("when removing styles", () => { | ||
it("should remove an associated stylesheet", () => { | ||
const cache = new Map(); | ||
const sheet = new AdoptedStyleSheetsStyles([``], cache); | ||
const target: Pick<StyleTarget, "adoptedStyleSheets"> = { | ||
adoptedStyleSheets: [], | ||
}; | ||
|
||
sheet.addStylesTo(target as StyleTarget); | ||
expect(target.adoptedStyleSheets!.length).to.equal(1); | ||
|
||
sheet.removeStylesFrom(target as StyleTarget); | ||
expect(target.adoptedStyleSheets!.length).to.equal(0); | ||
}); | ||
|
||
it("should not remove unassociated styles", () => { | ||
const cache = new Map(); | ||
const sheet = new AdoptedStyleSheetsStyles(["test"], cache); | ||
const style = new CSSStyleSheet(); | ||
const target: Pick<StyleTarget, "adoptedStyleSheets"> = { | ||
adoptedStyleSheets: [style], | ||
}; | ||
sheet.addStylesTo(target as StyleTarget); | ||
|
||
expect(target.adoptedStyleSheets!.length).to.equal(2); | ||
expect(target.adoptedStyleSheets).to.contain(cache.get("test")); | ||
|
||
sheet.removeStylesFrom(target as StyleTarget); | ||
|
||
expect(target.adoptedStyleSheets!.length).to.equal(1); | ||
expect(target.adoptedStyleSheets).not.to.contain(cache.get("test")); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters