【发布时间】:2016-10-30 17:19:59
【问题描述】:
我正在构建一个应用程序,但在处理代理查询和测试时遇到了一些麻烦。
我有以下测试:
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()
})
})
失败并抛出以下错误:
无法分配给#的只读属性“.js”
我试图简单地测试在我的 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)
}
}
知道出了什么问题吗?
【问题讨论】:
标签: javascript node.js jasmine proxyquire