|
| 1 | +/* eslint max-nested-callbacks: ["error", 6] */ |
| 2 | + |
1 | 3 | import { |
2 | 4 | createStore, |
3 | 5 | selectors, |
4 | 6 | actions, |
5 | | - makeSource |
| 7 | + makeSource, |
| 8 | + waitForState |
6 | 9 | } from "../../utils/test-head"; |
7 | 10 |
|
8 | 11 | import readFixture from "./helpers/readFixture"; |
@@ -48,42 +51,64 @@ const evaluationResult = { |
48 | 51 | describe("ast", () => { |
49 | 52 | describe("setEmptyLines", () => { |
50 | 53 | it("scopes", async () => { |
51 | | - const { dispatch, getState } = createStore(threadClient); |
| 54 | + const store = createStore(threadClient); |
| 55 | + const { dispatch, getState } = store; |
| 56 | + |
52 | 57 | const source = makeSource("scopes.js"); |
53 | 58 | await dispatch(actions.newSource(source)); |
54 | 59 | await dispatch(actions.loadSourceText({ id: "scopes.js" })); |
55 | 60 |
|
| 61 | + await waitForState(store, state => { |
| 62 | + const lines = getEmptyLines(state, source); |
| 63 | + return lines && lines.length > 0; |
| 64 | + }); |
| 65 | + |
56 | 66 | const emptyLines = getEmptyLines(getState(), source); |
57 | 67 | expect(emptyLines).toMatchSnapshot(); |
58 | 68 | }); |
59 | 69 | }); |
60 | 70 | describe("setSourceMetaData", () => { |
61 | 71 | it("should detect react components", async () => { |
62 | | - const { dispatch, getState } = createStore(threadClient); |
| 72 | + const store = createStore(threadClient); |
| 73 | + const { dispatch, getState } = store; |
63 | 74 | const source = makeSource("reactComponent.js"); |
64 | 75 | await dispatch(actions.newSource(source)); |
| 76 | + |
65 | 77 | await dispatch(actions.loadSourceText({ id: "reactComponent.js" })); |
| 78 | + await waitForState(store, state => { |
| 79 | + const metaData = getSourceMetaData(state, source.id); |
| 80 | + return metaData && metaData.isReactComponent; |
| 81 | + }); |
66 | 82 |
|
67 | 83 | const sourceMetaData = getSourceMetaData(getState(), source.id); |
68 | 84 | expect(sourceMetaData).toEqual({ isReactComponent: true }); |
69 | 85 | }); |
| 86 | + |
70 | 87 | it("should not give false positive on non react components", async () => { |
71 | | - const { dispatch, getState } = createStore(threadClient); |
| 88 | + const store = createStore(threadClient); |
| 89 | + const { dispatch, getState } = store; |
72 | 90 | const source = makeSource("base.js"); |
73 | 91 | await dispatch(actions.newSource(source)); |
74 | 92 | await dispatch(actions.loadSourceText({ id: "base.js" })); |
| 93 | + await waitForState(store, state => { |
| 94 | + const metaData = getSourceMetaData(state, source.id); |
| 95 | + return metaData && metaData.isReactComponent === false; |
| 96 | + }); |
75 | 97 |
|
76 | 98 | const sourceMetaData = getSourceMetaData(getState(), source.id); |
77 | 99 | expect(sourceMetaData).toEqual({ isReactComponent: false }); |
78 | 100 | }); |
79 | 101 | }); |
| 102 | + |
80 | 103 | describe("setSymbols", () => { |
81 | 104 | describe("when the source is loaded", () => { |
82 | 105 | it("should be able to set symbols", async () => { |
83 | | - const { dispatch, getState } = createStore(threadClient); |
| 106 | + const store = createStore(threadClient); |
| 107 | + const { dispatch, getState } = store; |
84 | 108 | const base = makeSource("base.js"); |
85 | 109 | await dispatch(actions.newSource(base)); |
86 | 110 | await dispatch(actions.loadSourceText({ id: "base.js" })); |
| 111 | + await waitForState(store, state => getSymbols(state, base)); |
87 | 112 |
|
88 | 113 | const baseSymbols = getSymbols(getState(), base); |
89 | 114 | expect(baseSymbols).toMatchSnapshot(); |
|
0 commit comments