2

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 ?


I think you are checking only $_FILES , also check post data print_r($_POST)

4

1 回答 1

0

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

import fetch from 'node-fetch';
import CONSTANTS from './constants';
于 2020-04-17T07:34:06.320 回答