Skip to content

const's and throws #18

@edsharp

Description

@edsharp

I've been comparing using rewire and mocks to see which best suits my needs.

Using node 5.6.0, I've noticed two things when using loadFile on a module:

  1. private const's aren't available unless I change them to var's
  2. private functions that throw errors don't seem to throw the same type of error as they do when they natively throw the error

I think 1. is caused because vm.runInNewContext does not seem to make the const's available on the context.

I'm not sure what causes 2.---although I suspect it's related to the 'displayErrors' option for runInNewContext---but the symptom is that:

// in module being loadFile'd
myFunc() {throw new Error('foo')}

// in test
should.Throw(myFunc(), Error, 'foo')

will not assert.

I'm not sure if there's anything that can easily be done about either of these, but I thought I'd bring them to your attention and I'm curious to hear your answers :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions