File size: 1,233 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
describe('toWarnDev', () => {
  describe('usage', () => {
    test('fails with incorrect type of message', () => {
      expect(() => {
        // @ts-ignore
        expect(() => {}).toWarnDev(false);
      }).toThrowErrorMatchingInlineSnapshot(
        `"toWarnDev() requires a parameter of type string but was given boolean."`
      );
    });
  });

  describe('without message', () => {
    test('does not fail if called', () => {
      expect(() => {
        expect(() => {
          console.warn('warning');
        }).toWarnDev();
      }).not.toThrow();
    });

    test('fails if not called', () => {
      expect(() => {
        expect(() => {}).toWarnDev();
      }).toThrowErrorMatchingInlineSnapshot(`"No warning recorded."`);
    });
  });

  describe('with message', () => {
    test('does not fail with correct message', () => {
      expect(() => {
        expect(() => {
          console.warn('warning');
        }).toWarnDev('warning');
      }).not.toThrow();
    });

    test('fails if a warning is not correct', () => {
      expect(() => {
        expect(() => {
          console.warn('warning');
        }).toWarnDev('another warning');
      }).toThrow(/Unexpected warning recorded./);
    });
  });
});