nodejs/mocha/nock - mocking an entire html response

How can I mock an entire HTML body response for my tests?

I'm using nodejs/mocha/nock.

With nock I can mock JSON responds just fine, for example:

nock('http://myapp.iriscouch.com')
                .get('/users/1')
                .reply(200, {_id: "123ABC", _rev: "946B7D1C", username: 'pgte'});

I used curl -o to fetch the html I want for the mock, so I have it already in a file - but I don't see how can I pass an HTML file to nock (or something else).

Thanks.

First fetch the HTML content of your test file and put it in a string (using fs.readFile for example)

after that you can do:

nock('http://myapp.iriscouch.com').
        get('/users/1').
        reply(200, yourFileContent);

This is what worked out for me in the past :)

If you'd like, you can specify the content type explicitly, since you specify the body as a string this will effectively let you mock any non-binary response easily:

nock('http://myapp.iriscouch.com').
        get('/users/1').
        reply(200, yourFileContent, {'content-type': 'text/html'});

If you want a more general approach, I've asked a more general question about a similar issue and got some interesting responses.