I m building a application and having some troubles dealing with proxyquire and testing.
I have the following test :
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()
})
})
That fails and throw me the following error :
Cannot asign to read only property '.js' of #
I m trying to simply test that fetch module has been called in my getAll method :
'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)
}
}
Any idea what's going wrong ?