Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.getMock() returns undefined #68

Closed
jarofghosts opened this issue Mar 1, 2016 · 5 comments
Closed

.getMock() returns undefined #68

jarofghosts opened this issue Mar 1, 2016 · 5 comments

Comments

@jarofghosts
Copy link

Using browserify + fetch-mock, attempts to get a reference to the mock via .getMock() always seems to return undefined.

A glance at the code indicates that getMock just returns this.fetch which doesn't seem to be set anywhere.

@wheresrhys
Copy link
Owner

Could you post a code sample and details of which browser please

@jarofghosts
Copy link
Author

require('isomorphic-fetch')

var mock = require('fetch-mock')

console.log(mock.getMock()) // undefined

mock.mock('lol/', 'ok')

console.log(mock.getMock()) // undefined

tried in chrome and phantomjs

@wheresrhys
Copy link
Owner

thanks, I'll investigate over the weekend

@wheresrhys
Copy link
Owner

I see, you're using the API incorrectly

getMock() is only intended for use when you're not mocking the global fetch instance and need a reference to the mocked function so you can assign it to a variable and use as a stub/spy.

What are you trying to use getMock for?

@jarofghosts
Copy link
Author

Very sorry! The code I presented here was just made up to try and reproduce in as few lines as possible, but it turns out that what I want to do actually does work, so I can close this.

const fetchMock = require('fetch-mock')

fetchMock.useNonGlobalFetch(require('isomorphic-fetch'))
fetchMock.mock('lol/', 'ok')

const mock = fetchMock.getMock() // works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants