无法分配给只读属性&#39; .js&#39; #<object>

时间:2016-06-28 11:39:43

标签: javascript node.js jasmine proxyquire

我正在构建一个应用程序,并且在处理代理和测试方面遇到了一些麻烦。

我有以下测试:

import proxyquire from 'proxyquire'
const fetchMock = () => new Promise((res) => {
  jobs: []
})
const JenkinsService = proxyquire('../lib/jenkins-service', {
  'node-fetch': fetchMock
})

describe('JenkinsService#getProject->goodConfs', () => {
      let service
      beforeEach(() => service = new JenkinsService({
        url: 'http://jenkins.io'
      }))

      it('should call fetch method', () => {
        service.getAll()
      })
    })

失败并向我发出以下错误:

  

无法只读取属性&#39; .js&#39;的#

我试图简单地测试在我的getAll方法中调用了fetch模块:

'use babel'
import fetch from 'node-fetch'
import CONSTANTS from './constants'

export default class JenkinsService {

  /**
   * Create a new JenkinsService
   * @param  {Object} configs The configuration needed to access jenkins
   */
  constructor (configs) {
    this.configs = configs
  }

  /**
   * Get a remote list of projects
   * @return {Object[]} The project list
   */
  getAll () {
    if (!this.configs.url) throw new Error(CONSTANTS.NO_URL_IN_CONFS)
    return fetch(this.configs.url)
  }
}

知道出了什么问题吗?

1 个答案:

答案 0 :(得分:0)

可能的解决方案,您应该在每个导入行的末尾添加分号

import fetch from 'node-fetch';
import CONSTANTS from './constants';