Closed fatso83 closed 9 years ago
Using require.resolve()
can help here
const mock = require('mock')
const test = require('tape')
const toUpload = mock(require.resolve('../stores/toUpload.js'), {
'react-native': {
AsyncStorage: {
getItem () {
console.log('getItem')
},
setItem () {
console.log('setItem')
}
}
}
})
const flux = mock(require.resolve('../flux.js'), {
[require.resolve('../stores/toUpload.js')]: toUpload
})
I've found that I need to surround all relative module paths with require.resolve()
. I wonder if this can somehow be avoided? Makes sense I guess.
Hmm.. might be. It's been 8 months, and I no longer work on this project anymore, so I won't be able to verify the solution. I'll close this, and hope that someone else will find your solution.
I cannot get this module to work at all.
just crashes Node with the error
The
require
statement on line 13 works fine, so I am not sure what is going on there. I also turned on the debugging statement which shows this going on just before the crash:This seems to indicate that it does not look for the module from the project root, but only in its node_modules directory. Or that it seems to regard the mock module as the actual package.