Problem trying to intercept a request
See original GitHub issueSorry if that is not the best to ask this.
But i am trying to use nock to mock the Shopify´s API, then i have some like this to get all blogs from a shop:
class Blog
constructor: (key, pass, shop) ->
throw new Error 'Blog missing parameters' if not pass? or not key? or not shop?
@options =
host: "http://#{key}:#{pass}@#{shop}.myshopify.com"
port: 80
method: "GET"
path: '/admin/blogs.json'
all: (cb) ->
req = request @options, (res) ->
response = ""
res.setEncoding('utf8')
res.on 'data', (data) ->
response += data
res.on 'end', ->
error = new Error 'Request Error #{res.statusCode}' unless res.statusCode is 200
process.nextTick ->
cb(error, JSON.parse(response))
req.end()
And parts of my testing they are some like this:
describe 'Receive a list of all Blogs', ->
before ->
@fixture = loadFixture 'blog/blogs'
@api = nock "https://#{KEY}:#{PASSWORD}@#{STORE}.myshopify.com"
@blog = new Blog KEY, PASSWORD, STORE
it 'should be possible get a list of all blog like an Array', (done) ->
@api.get('/admin/blogs.json').reply(200, @fixture)
@blog.all (err, blogs) =>
@api.done()
blogs.should.be.an.instanceof Object
done()
Sorry but i dont know what is wrong in my code, because allways get the response from the real server. But i need that my calls they are intercepting by nock to response my @fixture arrays of blogs.
Again sorry for ask that here.
Issue Analytics
- State:
- Created 12 years ago
- Comments:23 (12 by maintainers)
Top Results From Across the Web
Cypress cy.intercept Problems - Gleb Bahmutov
The command cy. intercept can match requests using a substring, a minimatch, or a regular expression. By default, it intercepts requests ...
Read more >Intercept HTTP requests - Mozilla - MDN Web Docs
To intercept HTTP requests, use the webRequest API. This API enables you to add listeners for various stages of making an HTTP request....
Read more >A Practical Guide to Intercepting Network Requests in Cypress
First things first - matching our url When using . intercept() command, there are two main questions that need to be resolved. How...
Read more >Interceptor not intercepting http requests (Angular 6)
In my case interceptor wasn't getting involved for service calls because I had imported HttpClientModule multiple times, for different ...
Read more >intercept - Cypress Documentation
Spy and stub network requests and responses. Tip: We recommend you read the Network Requests guide first. All intercepts are automatically cleared before....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sorry it’s just super hard for me to read coffeescript, I don’t understand it
Canonical example, in javascript:
Then
require('nock')
has to happen before your app is initialized. There is nothing nock can do if you don’t, since we need to appear first so that the http.request function gets wrapped.