Reputation: 41
I cannot get nockBack to record any fixtures, although it should do that. My test code looks as follows:
describe("#searchForProjects", function () {
beforeEach(function () {
nock.back.setMode("record");
this.con = getTestConnection(ApiType.Production);
});
it("finds a home project", async function () {
const { nockDone, context } = await nock.back("search_for_project.json");
await searchForProjects(this.con, "home:dancermak", {
idOnly: true,
exactMatch: true
}).should.eventually.deep.equal([
{
name: "home:dancermak",
apiUrl: normalizeUrl(ApiType.Production)
}
]);
nockDone();
});
});
Just running this specific test results in a NetConnectNotAllowedError: Nock: Disallowed net connect for $URL
.
I have tried including a nock.restore()
before the whole test, which results in the request going through, but nock doesn't bother recording anything.
The underlying code is using the https
module from nodejs, so that shouldn't be a problem?
Any help would be greatly appreciated.
Upvotes: 3
Views: 1342
Reputation: 23562
For me the problem was that I had a failing assertion in my test. This meant that nockDone
was not called and so no nocks were written to disk.
Upvotes: 0
Reputation: 41
I have finally managed to crack this and the solution is embarrassingly simple: recording must be activated before creating any http(s).request
calls. In my case it was obscured a bit as I have a class that on construction saves either http.request
or https.request
in a member variable. Activating the recorder beforehands solves the issue.
Upvotes: 1