Search code examples
node.jsmockingtddnock

nock: is there a way to get a list of unsatisfaedMocks?


I want to have a code like this:

describe('populate', function() {
    it('should grab ', function() {
        nock('http://someapi.com')
            .post('/attractions')
            .reply(200, [])

        return request
          .post('http://someapi.com/wrong')
          .send({destId: id})
          .catch(() => 
            expect(nock.unsatisfaedMocks()).is.eql(['http://someapi.com/wrong'])
          )
    })
})

Is it possible?


Solution

  • Of course you can

    we usually stick for assert.strictEqual(nock.isDone(), true, nock.pendingMocks())

    nock.isDone() checks if all defined nock are triggered (globally) nock.pendingMocks() returns array of not-called nocks