Skip to content

Commit

Permalink
Add test for sharing declaration across multiple components
Browse files Browse the repository at this point in the history
  • Loading branch information
winston0410 committed Aug 20, 2021
1 parent 672e905 commit 7b51f14
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/tokenizer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,45 @@ describe("when given multiple rules with identical declaration", function () {
});
});

describe("when given multiple components", function () {
describe("when given multiple rules with identical declaration", function () {
const code1 = `
<style>
.layout-1{
display: flex;
}
</style>`;

const code2 = `
<style>
.layout-2{
display: flex;
}
</style>`;

const classCache = {};
const declarationCache = {};
const tokenizer = createTokenizer(classCache, declarationCache);

const list = [
[code1, "index.svelte"],
[code2, "dummy.svelte"],
];

for (const [code, filename] of list) {
const ast = parse(code, { filename });
tokenizer.generateToken(ast.css, filename);
}

it("should share that token of that declaration in cache", function () {
expect(classCache).toStrictEqual({
"index.svelte": { "layout-1": { a: true } },
"dummy.svelte": { "layout-2": { a: true } },
});
});
});
});

describe("when given a javascript expression as class attribute", function () {
const code = `
<style>
Expand Down

0 comments on commit 7b51f14

Please sign in to comment.