File size: 1,022 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { nock, useNock } from '../index.js';

describe( 'useNock', () => {
	useNock();

	describe( 'Messy without useNock', () => {
		// eslint-disable-next-line jest/expect-expect
		test( 'sets up a persistent interceptor', () => {
			nock( 'wordpress.com' ).persist().get( '/me' ).reply( 200, { id: 42 } );
		} );
	} );

	describe( 'Illustration Block', () => {
		test( 'still sees the earlier persistent connection', () => {
			expect( nock.isDone() ).toBe( false );
		} );

		afterAll( () => nock.cleanAll() );
	} );

	describe( 'Clean with useNock', () => {
		useNock();

		test( 'sets up a persistent interceptor', () => {
			nock( 'wordpress.com' ).persist().get( '/me' ).reply( 200, { id: 42 } );

			expect( nock.isDone() ).toBe( false );
		} );

		test( 'persists inside the same `describe` block', () => {
			expect( nock.isDone() ).toBe( false );
		} );
	} );

	describe( 'Test Block', () => {
		test( 'should have reset all remaining nocks', () => {
			expect( nock.isDone() ).toBe( true );
		} );
	} );
} );