我正在使用public class MainActivity extends AppCompatActivity implements DrawerLayout.DrawerListener {
private DrawerLayout drawerLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
drawerLayout.setDrawerListener(this);
...
导入我的react / flux商店以进行单元测试。
这是测试文件的外观:
rewire
运行测试时,它显示错误,无法读取'use strict';
import {expect} from 'chai';
const rewire = require('rewire');
let SessionStore;
describe.only('Session Store', () => {
beforeEach(() => {
SessionStore = rewire('../../app/stores/SessionStore');
});
it('should ....', () => {
expect(1).to.equal(1);
});
});
未定义:
data
有谁知道如何解决这个问题?
PS。了解更多信息这是我正在使用的商店:
TypeError: Cannot read property 'data' of undefined
at eval (eval at <anonymous> (path/tests/stores/SessionStore.js:2346:2), <anonymous>:1:546)
at eval (eval at <anonymous> (path/tests/stores/SessionStore.js:2346:2), <anonymous>:1:677)
at Object.eval (eval at <anonymous> (path/tests/stores/SessionStore.js:2346:2), <anonymous>:177:9)
at Object.eval (eval at <anonymous> (path/tests/stores/SessionStore.js:2346:2), <anonymous>:178:30)
at Object.<anonymous> (path/tests/stores/SessionStore.js:2346:2)
at rewire (eval at <anonymous> (path/tests/stores/SessionStore.js:2340:2), <anonymous>:10:35)
at Context.eval (eval at <anonymous> (path/tests/stores/SessionStore.js:535:2), <anonymous>:50:20)
答案 0 :(得分:0)
我转到了同样的错误消息。
我在ES6中编写代码并使用karma运行测试。
我使用的所有重新布线模块都没有解决错误。
我终于安装了babel-rewire插件(https://www.npmjs.com/package/babel-rewire-plugin),在webpack配置完成后,一切顺利。