title: Disable a single nock scope immediately to re-setup a mocked URL
body: <p>Using <a href="https://github.com/nock/nock" rel="noreferrer">nock</a>, is there a way to disable a single nock scope?
  I've been struggling with some tests that set up nocks of the same URL as some other tests. They both run fine separately, but when run in the same mocha session one of them fails, because I'm unable to re-nock the active nock scopes, meaning the nocks that were set up catches all the requests.</p>
  
  <p>What I've tried:</p>
  
  <ul>
  <li>If I set up some nocks in <code>before()</code> and then call <code>scope.persist(false)</code> in my <code>after()</code>, it only "unpersists" the scope, so that it's active for <em>one more</em> request. It does not immediately disable it. </li>
  <li>I've found that <code>nock.cleanAll()</code> immediately disables the nocks so that they can be set up again, but then it <em>also</em> disables any global nocks that may have been set up once, common to all test cases.</li>
  </ul>
  
  <p>So far, the only solutions I've found are 1) use unique URL:s for all nocks, which isn't always possible or 2) use nock.cleanAll() and don't rely on any global nocks - instead make sure to only set up nocks in local <code>before()</code> functions, including setting up the global ones repeatedly for every test that needs them.</p>
  
  <p>It seems it would be highly useful to be able to do</p>
  
  <p><code>scope = nock('http://somewhere.com').persist().get('/'.reply(200, 'foo');</code></p>
  
  <p>and then use that nock in a bunch of tests, and finally do</p>
  
  <p><code>scope.remove();</code></p>
  
  <p>However, I've not been able to do something like this. Is it possible?</p>
  
  <p>Example:</p>
  
  <pre><code>before(async () =&gt; {
     nock('http://common').persist().get('/').reply(200, 'common');
  });
  
  after(async () =&gt; {
  });
  
  describe('Foo tests', () =&gt; {
      let scope;
      before(async () =&gt; {
          scope = nock('http://mocked').persist().get('/').reply(200, 'foo');
      });
      after(() =&gt; {
          // scope.persist(false); // This causes the Bar tests to use the Foo nocks one more time :(
          // nock.cleanAll(); // This also disables the common nocks
      });
      it('Should get FOO', async () =&gt; {
          expect(await fetch('http://mocked').then(res =&gt; res.text())).to.equal('foo');
          expect(await fetch('http://common').then(res =&gt; res.text())).to.equal('common');
      });
      it('Should get FOO again', async () =&gt; {
          expect(await fetch('http://mocked').then(res =&gt; res.text())).to.equal('foo');
          expect(await fetch('http://common').then(res =&gt; res.text())).to.equal('common');
      });
  });
  
  describe('Bar tests', () =&gt; {
      let scope;
      before(async () =&gt; {
          scope = nock('http://mocked').persist().get('/').reply(200, 'bar');
      });
      after(() =&gt; {
          // scope.persist(false);
          // nock.cleanAll();
      });
      it('Should get BAR', async () =&gt; {
          expect(await fetch('http://mocked').then(res =&gt; res.text())).to.equal('bar');
          expect(await fetch('http://common').then(res =&gt; res.text())).to.equal('common');
      });
      it('Should get BAR again', async () =&gt; {
          expect(await fetch('http://mocked').then(res =&gt; res.text())).to.equal('bar');
          expect(await fetch('http://common').then(res =&gt; res.text())).to.equal('common');
      });
  });
  </code></pre>
  
  <p>These tests either fail the 3rd test if using <code>scope.persist(false)</code> (since that test still gets the foo version), or fails tests 3 and 4 if using <code>nock.cleanAll()</code>, since the common nocks are then removed.</p>