-
Notifications
You must be signed in to change notification settings - Fork 0
/
reduxReselectCucumber.js
70 lines (57 loc) · 1.8 KB
/
reduxReselectCucumber.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const storeCreator = require("./src/state/store.js");
const initialState = require("./src/state/initialState.js");
const cucumber = (selector, { givens, whens, thens }, scenarioKey, givensMatchers, whensMatchers, thensMatchers) => {
let store;
givens.forEach(given => {
givensMatchers.forEach((givenMatcher) => {
const matches = [...given.matchAll(givenMatcher.matcher)]
if (matches.length === 1) {
store = storeCreator(initialState)
} else {
throw Error(`No Given for '${givenMatcher.matcher}'`);
}
})
});
whens.forEach(when => {
let found = false;
whensMatchers.forEach((whensMatcher) => {
const matches = [...when.matchAll(whensMatcher.matcher)]
if (matches.length === 1) {
store.dispatch({ type: whensMatcher.action, payload: whensMatcher.payload(matches) })
found = true;
}
});
if (!found) {
throw Error(`No WHEN for '${when}'`);
}
});
const computed = selector(store.getState());
thens.forEach(then => {
let found = false;
thensMatchers.forEach((thensMatcher) => {
const matches = [...then.matchAll(thensMatcher.matcher)]
if (matches.length === 1) {
it(scenarioKey, () => {
thensMatcher.assert(matches, computed);
});
found = true;
}
});
if (!found) {
throw Error(`No THEN for '${then}'`);
}
});
};
module.exports = (
componentTest, stateTest
) => {
const { scenarios, selector, thens } = componentTest;
const { givens, whens } = stateTest;
Object.keys(scenarios).forEach((descriptionKey) => {
describe(descriptionKey, () => {
Object.keys(scenarios[descriptionKey]).forEach((itKey) => {
cucumber(selector, scenarios[descriptionKey][itKey], itKey, givens, whens, thens)
})
});
})
};