加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 使用pouchdb设置karma单元测试

发布时间:2020-12-17 17:55:52 所属栏目:安全 来源:网络整理
导读:我想为使用pouchdb angular-pouchdb的角度应用程序设置单元测试. 但当我跑: 业力开始karma.conf.js 我收到以下错误: PhantomJS 1.9.7 (Mac OS X) ERROR TypeError: ‘undefined’ is not a function (evaluating ‘eventEmitter[method].bind(eventEmitter
我想为使用pouchdb angular-pouchdb的角度应用程序设置单元测试.
但当我跑:

业力开始karma.conf.js

我收到以下错误:

PhantomJS 1.9.7 (Mac OS X) ERROR

TypeError: ‘undefined’ is not a function (evaluating ‘eventEmitter[method].bind(eventEmitter)’)

at …/public/bower_components/pouchdb/dist/pouchdb-nightly.js:5758

角度应用程序在浏览器中运行良好,我所有的karma.conf.js文件都包含相同的依赖项,所以我不明白为什么pouchdb-nightly.js会有一个未定义的函数.
我错过了什么?

解决方法

这是一个常见错误:PhantomJS尚未实现Function.prototype.bind( here’s the bug),因此您需要 es5-shim.

或者你可以通过填充Function.prototype.bind而不是包括整个es5-shim库来实现.这是一个例子(摘自here):

(function () {
  'use strict';
  // minimal polyfill for phantomjs; in the future,we should do ES5_SHIM=true like pouchdb
  if (!Function.prototype.bind) {
    Function.prototype.bind = function (oThis) {
      if (typeof this !== "function") {
        // closest thing possible to the ECMAScript 5
        // internal IsCallable function
        throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
      }

      var aArgs = Array.prototype.slice.call(arguments,1),fToBind = this,fNOP = function () {},fBound = function () {
            return fToBind.apply(this instanceof fNOP && oThis
                   ? this
                   : oThis,aArgs.concat(Array.prototype.slice.call(arguments)));
          };

      fNOP.prototype = this.prototype;
      fBound.prototype = new fNOP();

      return fBound;
    };
  }
})();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读