使用酶进行Meteor / React Mocha测试 - 找不到模块'has'

时间:2016-06-28 07:00:06

标签: javascript meteor reactjs mocha enzyme

表示我正在使用React运行Meteor应用程序,并开始使用Mocha编写测试。目前我有一个基本的测试,没有测试任何东西。

的客户机/前景/ ProspectForm.tests.jsx

import React from 'react';
import { shallow } from 'enzyme';

describe('<Foo />', () => {

  it('calls componentDidMount', () => {
  });

});

当我启动测试服务器时,我收到以下错误

error

找不到模块'has'。看起来问题源于酶,但是当我创建一个新的流星应用程序并添加酶和practicalmeteor:mocha,然后添加相同的测试它工作正常,所以它必须与我的环境在这个应用程序上有关。

这是我的package.json

    {
  "name": "myApp",
  "private": true,
  "scripts": {
    "start": "meteor run"
  },
  "dependencies": {
    "material-ui": "^0.15.0",
    "meteor-node-stubs": "~0.2.0",
    "react": "^15.0.2",
    "react-addons-pure-render-mixin": "^15.0.1",
    "react-datepicker": "^0.27.0",
    "react-dom": "^15.0.2",
    "react-mounter": "^1.2.0",
    "react-s-alert": "^1.1.4",
    "react-tap-event-plugin": "^1.0.0"
  },
  "devDependencies": {
    "enzyme": "^2.3.0"
  }
}

这是我的meteor包文件

# edgee:slingshot                         # Send files to storage service.
# peerlibrary:aws-sdk                     # Amazon SDK for S3/EC2/etc...


# CORE PACKAGES
meteor-base                               # Meteor platform
mobile-experience                         # Mobile Optimizations
logging                                   # Meteor internal logging
ejson                                     # Extends JSON Types
tracker                                   # Reactive Data Sources
email                                     # Send emails
accounts-password                         # Authentication for users.
es5-shim                                  # ECMAScript 5 compatibility for older browsers.
ecmascript                                # Enable ECMAScript2015+ syntax
standard-minifier-css                     # CSS Minification
standard-minifier-js                      # Javascript Minification
static-html                               # Adds global head tag
reload                                    # Active reload
react-meteor-data                         # Used for react data mixins

stevezhu:lodash                           # Javascript utility library.
momentjs:moment                           # Date library for Javascript.
johnantoni:meteor-normalize               # normalizes css
fourseven:scss                            # SASS stylesheets.
fortawesome:fontawesome                   # Icons.
natestrauser:animate-css                  # Animations using CSS.
mongo                                     # Mongo DB
aldeed:collection2                        # Schemas and validations for database collections.
dburles:collection-helpers                # Create data helpers in ./lib available to client and server.
meteortoys:allthings                      # A number of helpers for deveopment. Activate with control+m
kadira:flow-router                        # Router.
mystor:device-detection                   # Detect device user is using.
semantic:ui-css
practicalmeteor:mocha

有谁知道这里发生了什么?

2 个答案:

答案 0 :(得分:1)

如果您还没有these 2 dependencies,还需要安装{{3}}:

npm i --save-dev react-addons-test-utils
npm i --save-dev react-dom

看起来你有反应,但你错过了test-utils。

答案 1 :(得分:0)

运行流星更新为我解决了这个问题,而且我确实必须做达文所说的。