Proxyquire shows error "Cannot find module"
Asked Answered
G

0

6

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

Meteor 1.6.1

meteortesting:[email protected]

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!

Glasser answered 26/3, 2019 at 10:3 Comment(1)
Sadly not as yetGlasser

© 2022 - 2024 — McMap. All rights reserved.