Skip to content

Commit 20dac73

Browse files
authored
Add enzyme testing. (react-grid-layout#1163)
* test(enzyme): add basic enzyme snapshot test * test(flow): make Layout a $ReadOnlyArray * test(RRGL): test that layouts is not modified * test(lifecycle): add deep snapshots * fix(webpack): remove esm mode for now, not useful * fix(test): rem chance so we're fully deterministic * test(travis): ensure node 12 sort algo doesn't blow up tests * fix(showcase): make random placement more appealing
1 parent 6ec7d74 commit 20dac73

21 files changed

+10681
-70
lines changed

.babelrc.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
"use strict";
1+
// @flow
2+
3+
const es6Compat = process.env.BABEL_ES_COMPAT === "6" || process.env.NODE_ENV === "test";
24

35
module.exports = {
46
presets: [
57
[
68
"@babel/preset-env",
79
{
8-
targets: "> 0.25%, not dead"
9-
}
10+
targets: es6Compat ? "maintained node versions" : "> 0.25%, not dead"
11+
},
1012
],
1113
"@babel/react",
1214
"@babel/preset-flow"

.eslintrc.json

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
"rules": {
1414
"no-console": 0,
1515
"no-use-before-define": [2, "nofunc"],
16+
"no-unused-vars": [1, {
17+
"argsIgnorePattern": "^(e|_.*)$",
18+
"vars": "local",
19+
"varsIgnorePattern": "(debug|^_)"
20+
}],
1621
"prefer-const": 2,
1722
"react/jsx-boolean-value": [2, "always"]
1823
},

.flowconfig

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
[libs]
1414
interfaces/
15+
flow-typed/
1516

1617
[options]
1718
emoji=true

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
language: node_js
22
node_js:
3-
- "node"
3+
- 8
4+
- 10
5+
- 12
46
- "lts/*"
57
script:
68
- make build test

Makefile

+6-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ clean:
1919

2020
dev:
2121
@$(BIN)/webpack-dev-server --config webpack-dev-server.config.js \
22-
--hot --progress --colors
22+
--hot --progress --colors
2323

2424
# Allows usage of `make install`, `make link`
2525
install link:
@@ -41,15 +41,18 @@ build-example:
4141

4242
view-example:
4343
env CONTENT_BASE="/examples/" node ./examples/generate.js
44-
@$(BIN)/webpack-dev-server --config webpack-examples.config.js --progress --colors
44+
@$(BIN)/webpack-dev-server --config webpack-examples.config.js --progress --colors
4545

4646
# FIXME flow is usually global
4747
lint:
4848
@$(BIN)/flow
4949
@$(BIN)/eslint --ext .js,.jsx $(LIB) $(TEST)
5050

5151
test:
52-
@$(BIN)/jest
52+
env NODE_ENV=test $(BIN)/jest
53+
54+
test-watch:
55+
env NODE_ENV=test $(BIN)/jest --watch
5356

5457
release-patch: build lint test
5558
@$(call release,patch)

flow-typed/npm/classnames_v2.x.x.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// flow-typed signature: a00cf41b09af4862583460529d5cfcb9
2+
// flow-typed version: c6154227d1/classnames_v2.x.x/flow_>=v0.104.x
3+
4+
type $npm$classnames$Classes =
5+
| string
6+
| { [className: string]: *, ... }
7+
| false
8+
| void
9+
| null;
10+
11+
declare module "classnames" {
12+
declare module.exports: (
13+
...classes: Array<$npm$classnames$Classes | $npm$classnames$Classes[]>
14+
) => string;
15+
}
16+
17+
declare module "classnames/bind" {
18+
declare module.exports: $Exports<"classnames">;
19+
}
20+
21+
declare module "classnames/dedupe" {
22+
declare module.exports: $Exports<"classnames">;
23+
}

flow-typed/npm/enzyme_v3.x.x.js

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
// flow-typed signature: 931d5482afcb022bcbddb841fd08d683
2+
// flow-typed version: 5175c53189/enzyme_v3.x.x/flow_>=v0.104.x
3+
4+
declare module "enzyme" {
5+
declare type PredicateFunction<T: Wrapper<*>> = (
6+
wrapper: T,
7+
index: number
8+
) => boolean;
9+
declare type UntypedSelector = string | { [key: string]: number|string|boolean, ... };
10+
declare type EnzymeSelector = UntypedSelector | React$ElementType;
11+
12+
// CheerioWrapper is a type alias for an actual cheerio instance
13+
// TODO: Reference correct type from cheerio's type declarations
14+
declare type CheerioWrapper = any;
15+
16+
declare class Wrapper<RootComponent> {
17+
equals(node: React$Element<any>): boolean,
18+
find(selector: UntypedSelector): this,
19+
find<T: React$ElementType>(selector: T): ReactWrapper<T>,
20+
findWhere(predicate: PredicateFunction<this>): this,
21+
filter(selector: UntypedSelector): this,
22+
filter<T: React$ElementType>(selector: T): ReactWrapper<T>,
23+
filterWhere(predicate: PredicateFunction<this>): this,
24+
hostNodes(): this,
25+
contains(nodes: React$Node): boolean,
26+
containsMatchingElement(node: React$Node): boolean,
27+
containsAllMatchingElements(nodes: React$Node): boolean,
28+
containsAnyMatchingElements(nodes: React$Node): boolean,
29+
dive(option?: { context?: Object, ... }): this,
30+
exists(selector?: EnzymeSelector): boolean,
31+
isEmptyRender(): boolean,
32+
matchesElement(node: React$Node): boolean,
33+
hasClass(className: string): boolean,
34+
is(selector: EnzymeSelector): boolean,
35+
isEmpty(): boolean,
36+
not(selector: EnzymeSelector): this,
37+
children(selector?: UntypedSelector): this,
38+
children<T: React$ElementType>(selector: T): ReactWrapper<T>,
39+
childAt(index: number): this,
40+
parents(selector?: UntypedSelector): this,
41+
parents<T: React$ElementType>(selector: T): ReactWrapper<T>,
42+
parent(): this,
43+
closest(selector: UntypedSelector): this,
44+
closest<T: React$ElementType>(selector: T): ReactWrapper<T>,
45+
render(): CheerioWrapper,
46+
renderProp(propName: string): (...args: Array<any>) => this,
47+
unmount(): this,
48+
text(): string,
49+
html(): string,
50+
invoke(propName: string): (...args: $ReadOnlyArray<any>) => mixed,
51+
get(index: number): React$Node,
52+
getDOMNode(): HTMLElement | HTMLInputElement,
53+
at(index: number): this,
54+
first(): this,
55+
last(): this,
56+
state(key?: string): any,
57+
context(key?: string): any,
58+
props(): Object,
59+
prop(key: string): any,
60+
key(): string,
61+
simulate(event: string, ...args: Array<any>): this,
62+
simulateError(error: Error): this,
63+
slice(begin?: number, end?: number): this,
64+
setState(state: {...}, callback?: () => void): this,
65+
setProps(props: {...}, callback?: () => void): this,
66+
setContext(context: Object): this,
67+
instance(): React$ElementRef<RootComponent>,
68+
update(): this,
69+
debug(options?: Object): string,
70+
type(): string | Function | null,
71+
name(): string,
72+
forEach(fn: (node: this, index: number) => mixed): this,
73+
map<T>(fn: (node: this, index: number) => T): Array<T>,
74+
reduce<T>(
75+
fn: (value: T, node: this, index: number) => T,
76+
initialValue?: T
77+
): Array<T>,
78+
reduceRight<T>(
79+
fn: (value: T, node: this, index: number) => T,
80+
initialValue?: T
81+
): Array<T>,
82+
some(selector: EnzymeSelector): boolean,
83+
someWhere(predicate: PredicateFunction<this>): boolean,
84+
every(selector: EnzymeSelector): boolean,
85+
everyWhere(predicate: PredicateFunction<this>): boolean,
86+
length: number
87+
}
88+
89+
declare class ReactWrapper<T> extends Wrapper<T> {
90+
constructor(nodes: React$Element<T>, root: any, options?: ?Object): ReactWrapper<T>,
91+
mount(): this,
92+
ref(refName: string): this,
93+
detach(): void
94+
}
95+
96+
declare class ShallowWrapper<T> extends Wrapper<T> {
97+
constructor(
98+
nodes: React$Element<T>,
99+
root: any,
100+
options?: ?Object
101+
): ShallowWrapper<T>,
102+
equals(node: React$Node): boolean,
103+
shallow(options?: { context?: Object, ... }): ShallowWrapper<T>,
104+
getElement(): React$Node,
105+
getElements(): Array<React$Node>
106+
}
107+
108+
declare function shallow<T>(
109+
node: React$Element<T>,
110+
options?: {
111+
context?: Object,
112+
disableLifecycleMethods?: boolean,
113+
...
114+
}
115+
): ShallowWrapper<T>;
116+
declare function mount<T>(
117+
node: React$Element<T>,
118+
options?: {
119+
context?: Object,
120+
attachTo?: HTMLElement,
121+
childContextTypes?: Object,
122+
...
123+
}
124+
): ReactWrapper<T>;
125+
declare function render(
126+
node: React$Node,
127+
options?: { context?: Object, ... }
128+
): CheerioWrapper;
129+
130+
declare module.exports: {
131+
configure(options: {
132+
Adapter?: any,
133+
disableLifecycleMethods?: boolean,
134+
...
135+
}): void,
136+
render: typeof render,
137+
mount: typeof mount,
138+
shallow: typeof shallow,
139+
ShallowWrapper: typeof ShallowWrapper,
140+
ReactWrapper: typeof ReactWrapper,
141+
...
142+
};
143+
}

0 commit comments

Comments
 (0)