Skip to content

Commit 1b5b86e

Browse files
authored
update testcase (#33)
1 parent 553a6c3 commit 1b5b86e

File tree

2 files changed

+68
-5
lines changed

2 files changed

+68
-5
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-styled",
3-
"version": "0.31.0",
3+
"version": "0.32.0",
44
"description": "PostCSS syntax for parsing styled components",
55
"repository": {
66
"type": "git",
@@ -34,15 +34,15 @@
3434
},
3535
"peerDependencies": {
3636
"postcss": ">=5.0.0",
37-
"postcss-syntax": ">=0.31.0"
37+
"postcss-syntax": ">=0.32.0"
3838
},
3939
"devDependencies": {
4040
"chai": "^4.1.2",
4141
"codecov": "^3.0.4",
4242
"mocha": "^5.2.0",
4343
"nyc": "^12.0.2",
44-
"postcss": "^7.0.0",
44+
"postcss": "^7.0.1",
4545
"postcss-safe-parser": "^4.0.1",
46-
"postcss-syntax": ">=0.31.0"
46+
"postcss-syntax": ">=0.32.0"
4747
}
4848
}

test/styled-components.js

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("styled-components", () => {
3333
it("empty template literal", () => {
3434
const code = [
3535
"function test() {",
36-
" console.log(`debug`)",
36+
" alert`debug`",
3737
" return ``;",
3838
"}",
3939
"",
@@ -169,4 +169,67 @@ describe("styled-components", () => {
169169
expect(document.nodes).to.have.lengthOf(1);
170170
expect(document.first.first).to.haveOwnProperty("prop", "margin-${/* sc-custom 'left' */ rtlSwitch}");
171171
});
172+
173+
it("lazy assignment", () => {
174+
const code = [
175+
"let myDiv;",
176+
"myDiv = require(\"styled-components\").div;",
177+
"myDiv`a{}`;",
178+
].join("\n");
179+
const document = syntax.parse(code, {
180+
from: "lazy_assign.js",
181+
});
182+
expect(document.toString()).to.equal(code);
183+
expect(document.source).to.haveOwnProperty("lang", "jsx");
184+
expect(document.nodes).to.have.lengthOf(1);
185+
});
186+
187+
it("lazy assignment without init", () => {
188+
const code = [
189+
"myDiv = require(\"styled-components\").div;",
190+
"myDiv`a{}`;",
191+
].join("\n");
192+
const document = syntax.parse(code, {
193+
from: "lazy_assign_no_init.js",
194+
});
195+
expect(document.toString()).to.equal(code);
196+
expect(document.source).to.haveOwnProperty("lang", "jsx");
197+
expect(document.nodes).to.have.lengthOf(1);
198+
});
199+
200+
it("array destructuring assignment", () => {
201+
const code = [
202+
"const [",
203+
"\tstyledDiv,",
204+
"\t...c",
205+
"] = require(\"styled-components\");",
206+
"styledDiv`a{}`;",
207+
].join("\n");
208+
const document = syntax.parse(code, {
209+
from: "arr_destructuring.js",
210+
});
211+
expect(document.toString()).to.equal(code);
212+
expect(document.source).to.haveOwnProperty("lang", "jsx");
213+
expect(document.nodes).to.have.lengthOf(1);
214+
});
215+
216+
it("object destructuring assignment", () => {
217+
const code = [
218+
"const {",
219+
"\t// commit",
220+
"\t['div']: styledDiv,",
221+
"\ta,",
222+
"\t...styled",
223+
"} = require(\"styled-components\");",
224+
"styledDiv`a{}`;",
225+
"styled.div`a{}`;",
226+
"a`a{}`;",
227+
].join("\n");
228+
const document = syntax.parse(code, {
229+
from: "obj_destructuring.js",
230+
});
231+
expect(document.toString()).to.equal(code);
232+
expect(document.source).to.haveOwnProperty("lang", "jsx");
233+
expect(document.nodes).to.have.lengthOf(3);
234+
});
172235
});

0 commit comments

Comments
 (0)