-1

我有一个名为redux-scripts

<link rel="import" href="../config.html">
<script src="../../node_modules/redux/dist/redux.min.js"></script>
<script src="../../bower_components/amazon-cognito-identity-js/dist/aws-cognito-sdk.min.js"></script>
<script src="../../bower_components/amazon-cognito-identity-js/dist/amazon-cognito-identity.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux-promise-middleware/4.4.1/redux-promise-middleware.min.js"></script>
<script src="./redux-promises.js"></script>

我在顶部导入redux-mixin.html

<link rel="import" href="../../bower_components/polymer-redux/polymer-redux.html">
<script src="../../bower_components/aws-sdk/dist/aws-sdk.min.js"></script>
<link rel="import" href="redux-scripts.html">

<script type="module" src="./index.js"></script>
<script nomodule src="./bundle.js"></script>

在 Chrome 和 firefox 中运行起来就像一个魅力,但是当涉及到 web 组件测试器时:

redux-store.js:22 Uncaught ReferenceError: ReduxPromiseMiddleware is not defined
at redux-store.js:22

这是指

import programs from './programs/programsReducer.js';
import videos from './videos/videosReducer.js';
import video from './video/videoReducer.js';

const rootReducer = Redux.combineReducers({
  programs,
  videos,
  video,
});

// Setup a Redux store
const initialState = {
  viewSpecificToolbar: 'videos',
};

const store = Redux.createStore(
  rootReducer,
  initialState,

  // The best part 8)
  Redux.compose(
    Redux.applyMiddleware(ReduxPromiseMiddleware.default()),
    window.devToolsExtension ? window.devToolsExtension() : (v) => v
  )
);

export {store};

我通过将其添加到 redux-store.js 的顶部实现了部分解决方法

const scripts = Polymer.ResolveUrl.resolveUrl('./redux-scripts.html');
Polymer.importHref(scripts, null, null, false);

但这并不是特别令人满意,因为它在运行测试时会导致很多错误,而且并不是所有的测试套件都能运行。

4

1 回答 1

0

另一种解决方案是将redux-scripts.html导入添加到所有测试文件,但是,通过更改 redux-promise-middleware 库获得了更好的解决方案。在 4.4.2 版本中,index.js 中的 import 语句现在指向./isPromise.js带有文件扩展名的相对路径。有了这个,我就可以import promiseMiddleware from '../../node_modules/redux-promise-middleware/dist/es/index.js'进去了redux-store.js,我们是金色的。

于 2017-11-02T23:07:12.000 回答