Skip to content

Commit e767953

Browse files
committed
test: proper test suite
1 parent 4eb500d commit e767953

13 files changed

+92
-55
lines changed
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:local(.Label) {
2+
color: red
3+
}

src/__tests__/fixtures/custom-base.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from "react";
2+
import styles from "css";
3+
export function Label(props) {
4+
return React.createElement("span", { ...props, className: styles.Label
5+
});
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Label {
2+
base: span;
3+
color: red;
4+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
:local(.Label) {
2+
color: red
3+
}
4+
:local(.Label:hover) {
5+
color: white
6+
}
7+
:local(.Label:hover:focus) {
8+
color: black
9+
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from "react";
2+
import styles from "css";
3+
export function Label(props) {
4+
return React.createElement("div", { ...props, className: styles.Label
5+
});
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Label {
2+
color: red;
3+
:hover {
4+
color: white;
5+
:focus {
6+
color: black;
7+
}
8+
}
9+
}

src/__tests__/fixtures/pseudo.css

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
:local(.Label) {
2+
color: red
3+
}
4+
:local(.Label:hover) {
5+
color: white
6+
}

src/__tests__/fixtures/pseudo.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from "react";
2+
import styles from "css";
3+
export function Label(props) {
4+
return React.createElement("div", { ...props, className: styles.Label
5+
});
6+
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Label {
2+
color: red;
3+
:hover {
4+
color: white;
5+
}
6+
}

src/__tests__/fixtures/simple.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:local(.Label) {
2+
color: red
3+
}

src/__tests__/fixtures/simple.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from "react";
2+
import styles from "css";
3+
export function Label(props) {
4+
return React.createElement("div", { ...props, className: styles.Label
5+
});
6+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Label {
2+
color: red;
3+
}

src/__tests__/index-test.js

+25-55
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,37 @@
1+
/**
2+
* @copyright 2016-present, React CSS Components team
3+
* @flow
4+
*/
5+
6+
import assert from 'assert';
7+
import fs from 'fs';
8+
import path from 'path';
19
import {render} from '../';
210

3-
describe('react-css-components', function() {
4-
5-
it('renders react compoents', function() {
6-
let {js, css} = render(`
7-
8-
Label {
9-
color: red;
10-
}
11-
`, {requestCSS: 'react-css-components?css!styles.react.css'});
12-
console.log('--- js');
13-
console.log(js);
14-
console.log('--- css');
15-
console.log(css);
16-
});
17-
11+
const REACT_CSS_RE = /\.react\.css$/;
1812

19-
it('renders react components with pseudoclasses', function() {
20-
let {js, css} = render(`
13+
describe('react-css-components', function() {
2114

22-
Label {
23-
color: red;
24-
:hover {
25-
color: white;
15+
function readFixture(filename) {
16+
filename = path.join(__dirname, 'fixtures', filename);
17+
return fs.readFileSync(filename, 'utf8').trim();
2618
}
27-
}
28-
`, {requestCSS: 'react-css-components?css!styles.react.css'});
29-
console.log('--- js');
30-
console.log(js);
31-
console.log('--- css');
32-
console.log(css);
33-
});
3419

35-
it('renders react components with nested pseudoclasses', function() {
36-
let {js, css} = render(`
20+
fs.readdirSync(path.join(__dirname, 'fixtures')).forEach(filename => {
3721

38-
Label {
39-
color: red;
40-
:hover {
41-
color: white;
42-
:focus {
43-
color: black;
22+
if (!REACT_CSS_RE.exec(filename)) {
23+
return;
4424
}
45-
}
46-
}
47-
`, {requestCSS: 'react-css-components?css!styles.react.css'});
48-
console.log('--- js');
49-
console.log(js);
50-
console.log('--- css');
51-
console.log(css);
52-
});
25+
let jsExpect = filename.replace(REACT_CSS_RE, '.js');
26+
let cssExpect = filename.replace(REACT_CSS_RE, '.css');
5327

54-
it('renders react components based on specified DOM component', function() {
55-
let {js, css} = render(`
28+
it('renders: ' + filename, function() {
29+
let source = readFixture(filename);
30+
let {js, css} = render(source, {requestCSS: 'css'});
31+
assert.equal(js, readFixture(jsExpect));
32+
assert.equal(css, readFixture(cssExpect));
33+
});
5634

57-
Label {
58-
base: span;
59-
color: red;
60-
}
61-
`, {requestCSS: 'react-css-components?css!styles.react.css'});
62-
console.log('--- js');
63-
console.log(js);
64-
console.log('--- css');
65-
console.log(css);
6635
});
36+
6737
});

0 commit comments

Comments
 (0)