File size: 2,085 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
describe('useWatch', () => {
  it('should only trigger render when interact with input 1', () => {
    cy.visit('http://localhost:3000/useWatch');
    cy.get('input[name="test"]').type('t');

    cy.get('#parentCounter').contains('2');
    cy.get('#childCounter').contains('2');
    cy.get('#grandChildCounter').contains('3');
    cy.get('#grandChild1Counter').contains('3');
    cy.get('#grandChild2Counter').contains('3');
    cy.get('#grandchild01').contains('t');
    cy.get('#grandchild00').contains('t');

    cy.get('input[name="test"]').type('h');
    cy.get('#grandchild00').contains('th');
    cy.get('#grandchild01').contains('th');
    cy.get('#grandchild2').contains('t');
  });

  it('should only trigger render when interact with input 2', () => {
    cy.visit('http://localhost:3000/useWatch');
    cy.get('input[name="test1"]').type('h');

    cy.get('#parentCounter').contains('2');
    cy.get('#childCounter').contains('2');
    cy.get('#grandChildCounter').contains('3');
    cy.get('#grandChild1Counter').contains('3');
    cy.get('#grandChild2Counter').contains('3');

    cy.get('input[name="test1"]').type('h');
    cy.get('input[name="test"]').type('h');
    cy.get('#grandchild00').contains('h');
    cy.get('#grandchild01').contains('h');
    cy.get('#grandchild1').contains('hh');
    cy.get('#grandchild2').contains('hhh');
  });

  it('should only trigger render when interact with input 3', () => {
    cy.visit('http://localhost:3000/useWatch');
    cy.get('input[name="test2"]').type('e');

    cy.get('#parentCounter').contains('2');
    cy.get('#childCounter').contains('2');
    cy.get('#grandChildCounter').contains('3');
    cy.get('#grandChild1Counter').contains('3');
    cy.get('#grandChild2Counter').contains('3');

    cy.get('input[name="test2"]').type('eh');

    cy.get('input[name="test1"]').type('eh');
    cy.get('input[name="test"]').type('eh');
    cy.get('#grandchild00').contains('eh');
    cy.get('#grandchild01').contains('eh');
    cy.get('#grandchild1').contains('eh');
    cy.get('#grandchild2').contains('eheheeh');
  });
});