mardi 26 mars 2019

Proxyquire shows error "Cannot find module"

I'm trying to use proxyquire to replace a private function for testing in my Meteor app.

Meteor 1.6.1

meteortesting:mocha@1.1.2

In my parentFunction.js:

import { some function } from 'anotherFile';

function childFunction() {
  ...
  return someValue;
}

export default function parentFunction() {
  return childFunction()
}

In my test file:

const proxyquire = require('proxyquire');

if (Meteor.isServer) {
  ...

  describe('parentFunction', () => {
    it('uses the mocked child function', () => {
      const testThing = proxyquire('./parentFunction', {
        'childFunction': () => ({ 'name': 'bob' }),
      });
  });
}

parentFunction.js is in the same folder as my test file, and just to double check the path, I made sure this works:

import parentFunction from './parentFunction';

But when I run the test, I'm seeing an error:

Error: Cannot find module './parentFunction.js'

What am I doing wrong? I've tried an absolute path, that didn't work. And as far as I can see from the documentation a relative path in the file where proxiquire is required, should be fine.

Thanks for any help!

Aucun commentaire:

Enregistrer un commentaire