Example #1
0
 ].forEach(([n1, n2]) => {
   it(`throws expect(${stringify(n1)}).toMatchObject(${stringify(n2)})`, () => {
     expect(() =>
       jestExpect(n1).toMatchObject(n2),
     ).toThrowErrorMatchingSnapshot();
   });
 });
Example #2
0
 ].forEach(([a, b]) => {
   test(`{pass: false} expect(${stringify(a)}).not.toEqual(${stringify(
     b,
   )})`, () => {
     expect(() => jestExpect(a).not.toEqual(b)).toThrowErrorMatchingSnapshot();
   });
 });
Example #3
0
 ].forEach(([list, v]) => {
   it(`'${stringify(list)}' contains a value equal to '${stringify(v)}'`, () => {
     jestExpect(list).toContainEqual(v);
     expect(() =>
       jestExpect(list).not.toContainEqual(v)).toThrowErrorMatchingSnapshot();
   });
 });
Example #4
0
 ].forEach(([n1, n2]) => {
   it(`{pass: false} expect(${stringify(n1)}).toMatchObject(${stringify(n2)})`, () => {
     jestExpect(n1).not.toMatchObject(n2);
     expect(() =>
       jestExpect(n1).toMatchObject(n2)).toThrowErrorMatchingSnapshot();
   });
 });
Example #5
0
 ].forEach(([list, v]) => {
   it(`'${stringify(list)}' does not contain '${stringify(v)}'`, () => {
     jestExpect(list).not.toContain(v);
     expect(() => jestExpect(list).toContain(v))
       .toThrowError(/expected.*to contain.*/);
   });
 });
Example #6
0
  ].forEach(([a, b]) => {
    test(`failing ${stringify(a)} and ${stringify(b)}`, () => {
      expect(() =>
        jestExpect(a).toBeInstanceOf(b)).toThrowErrorMatchingSnapshot();

      jestExpect(a).not.toBeInstanceOf(b);
    });
  });
Example #7
0
  ].forEach(([list, v]) => {
    it(`'${stringify(list)}' does not contain '${stringify(v)}'`, () => {
      jestExpect(list).not.toContain(v);

      expect(() =>
        jestExpect(list).toContain(v)).toThrowErrorMatchingSnapshot();
    });
  });
Example #8
0
 ].forEach(([obj, keyPath, value]) => {
   test(`{pass: false} expect(${stringify(obj)}).toHaveProperty('${keyPath}', ${stringify(value)})`, () => {
     expect(() =>
       jestExpect(obj).toHaveProperty(keyPath, value),
     ).toThrowErrorMatchingSnapshot();
     jestExpect(obj).not.toHaveProperty(keyPath, value);
   });
 });
Example #9
0
  [[new Map(), Map], [[], Array], [new A(), A]].forEach(([a, b]) => {
    test(`passing ${stringify(a)} and ${stringify(b)}`, () => {
      expect(() =>
        jestExpect(a).not.toBeInstanceOf(b)).toThrowErrorMatchingSnapshot();

      jestExpect(a).toBeInstanceOf(b);
    });
  });
Example #10
0
  [[[{a: 'b'}, {a: 'c'}], {a: 'd'}]].forEach(([list, v]) => {
    it(`'${stringify(list)}' does not contain a value equal to'${stringify(v)}'`, () => {
      jestExpect(list).not.toContainEqual(v);

      expect(() =>
        jestExpect(list).toContainEqual(v)).toThrowErrorMatchingSnapshot();
    });
  });
Example #11
0
 ].forEach(([n1, n2]) => {
   it(
     `throws if non String/RegExp expected value passed:` +
       ` [${stringify(n1)}, ${stringify(n2)}]`,
     () => {
       matchErrorSnapshot(() => jestExpect(n1).toMatch(n2));
     },
   );
 });
Example #12
0
 ].forEach(([n1, n2]) => {
   it(
     'throws if non String actual value passed:' +
       ` [${stringify(n1)}, ${stringify(n2)}]`,
     () => {
       matchErrorSnapshot(() => jestExpect(n1).toMatch(n2));
     },
   );
 });
Example #13
0
 ].forEach(([n1, n2]) => {
   it(
     'throws if non String actual value passed:' +
       ` [${stringify(n1)}, ${stringify(n2)}]`,
     () => {
       expect(() => jestExpect(n1).toMatch(n2))
         .toThrowError(/is not a String/);
       jestExpect(n1).not.toMatch(n2);
     },
   );
 });
Example #14
0
 ].forEach(([n1, n2]) => {
   it(
     `throws if non String/RegExp expected value passed:` +
       ` [${stringify(n1)}, ${stringify(n2)}]`,
     () => {
       expect(() => jestExpect(n1).toMatch(n2))
         .toThrowError(/is not a String or a RegExp/);
       jestExpect(n1).not.toMatch(n2);
     },
   );
 });
Example #15
0
  ].forEach(([a, b]) => {
    it(`fails for: ${stringify(a)} and ${stringify(b)}`, () => {
      let error;

      try {
        jestExpect(a).toBe(b);
      } catch (e) {
        error = e;
      }

      expect(error).toBeDefined();
      expect(error.message).toMatchSnapshot();
    });
  });
Example #16
0
 ].forEach(([obj, keyPath]) => {
   test(`{error} expect(${stringify(obj)}).toHaveProperty('${keyPath}')`, () => {
     expect(() =>
       jestExpect(obj).toHaveProperty(keyPath),
     ).toThrowErrorMatchingSnapshot();
   });
 });
Example #17
0
 [{}, [], true, 1, 'a', 0.5, new Map(), () => {}, Infinity].forEach(v => {
   test(`fails for '${stringify(v)}' with .not`, () => {
     jestExpect(v).not.toBeNull();
     expect(() => jestExpect(v).toBeNull())
       .toThrowError(/expected.*to be null/);
   });
 });
Example #18
0
  [{}, [], true, 1, 'a', 0.5, new Map(), () => {}, Infinity].forEach(v => {
    test(`fails for '${stringify(v)}'`, () => {
      jestExpect(v).not.toBeNull();

      expect(() => jestExpect(v).toBeNull()).toThrowErrorMatchingSnapshot();
    });
  });
Example #19
0
 ].forEach(([received, length]) => {
   test(`{pass: false} expect(${stringify(received)}).toHaveLength(${length})`, () => {
     jestExpect(received).not.toHaveLength(length);
     expect(() =>
       jestExpect(received).toHaveLength(length),
     ).toThrowErrorMatchingSnapshot();
   });
 });
Example #20
0
 [false, null, NaN, 0, '', undefined].forEach(v => {
   test(`'${stringify(v)}' is falsy`, () => {
     jestExpect(v).toBeFalsy();
     jestExpect(v).not.toBeTruthy();
     matchErrorSnapshot(() => jestExpect(v).toBeTruthy());
     matchErrorSnapshot(() => jestExpect(v).not.toBeFalsy());
   });
 });
Example #21
0
 ].forEach(([obj, keyPath]) => {
   test(`{pass: true} expect(${stringify(obj)}).toHaveProperty('${keyPath}')'`, () => {
     jestExpect(obj).toHaveProperty(keyPath);
     expect(() =>
       jestExpect(obj).not.toHaveProperty(keyPath),
     ).toThrowErrorMatchingSnapshot();
   });
 });
Example #22
0
 [{}, [], true, 1, 'a', 0.5, new Map(), () => {}, Infinity].forEach(v => {
   test(`'${stringify(v)}' is defined`, () => {
     jestExpect(v).toBeDefined();
     jestExpect(v).not.toBeUndefined();
     matchErrorSnapshot(() => jestExpect(v).not.toBeDefined());
     matchErrorSnapshot(() => jestExpect(v).toBeUndefined());
   });
 });
Example #23
0
 [{}, [], true, 1, 'a', 0.5, new Map(), () => {}, Infinity].forEach(v => {
   test(`'${stringify(v)}' is truthy`, () => {
     jestExpect(v).toBeTruthy();
     jestExpect(v).not.toBeFalsy();
     matchErrorSnapshot(() => jestExpect(v).not.toBeTruthy());
     matchErrorSnapshot(() => jestExpect(v).toBeFalsy());
   });
 });
Example #24
0
 [false, null, NaN, 0, '', undefined].forEach(v => {
   test(`'${stringify(v)}' is falsy`, () => {
     jestExpect(v).toBeFalsy();
     jestExpect(v).not.toBeTruthy();
     expect(() => jestExpect(v).toBeTruthy()).toThrowError(/truthy/);
     expect(() => jestExpect(v).not.toBeFalsy())
       .toThrowError(/not to be falsy/);
   });
 });
Example #25
0
 [{}, [], true, 1, 'a', 0.5, new Map(), () => {}, Infinity].forEach(v => {
   test(`'${stringify(v)}' is truthy`, () => {
     jestExpect(v).toBeTruthy();
     jestExpect(v).not.toBeFalsy();
     expect(() => jestExpect(v).not.toBeTruthy())
       .toThrowError(/not to be truthy/);
     expect(() => jestExpect(v).toBeFalsy()).toThrowError(/falsy/);
   });
 });
Example #26
0
 [{}, [], true, 1, 'a', 0.5, new Map(), () => {}, Infinity].forEach(v => {
   test(`'${stringify(v)}' is defined`, () => {
     jestExpect(v).toBeDefined();
     jestExpect(v).not.toBeUndefined();
     expect(() => jestExpect(v).not.toBeDefined())
       .toThrowError(/not to be defined/);
     expect(() => jestExpect(v).toBeUndefined())
       .toThrowError(/to be undefined/);
   });
 });
Example #27
0
 [4, [1], {a: 1}, 'a', true, null, undefined, () => {}].forEach(value => {
   it(`fails non-promise value ${stringify(value)} synchronously`, () => {
     let error;
     try {
       jestExpect(value).rejects.toBe(111);
     } catch (e) {
       error = e;
     }
     expect(error).toBeDefined();
   });
 });
Example #28
0
 [4, [1], {a: 1}, 'a', true, null, undefined, () => {}].forEach(value => {
   it(`fails non-promise value ${stringify(value)}`, async () => {
     let error;
     try {
       await jestExpect(value).resolves.toBeDefined();
     } catch (e) {
       error = e;
     }
     expect(error).toBeDefined();
     expect(error.message).toMatchSnapshot();
   });
 });
Example #29
0
 [[[1, 2], 3], [[], 1], [['a', 'b'], 99], ['abc', 66], ['', 1]].forEach(([
   received,
   length,
 ]) => {
   test(`{pass: false} expect(${stringify(received)}).toHaveLength(${length})`, () => {
     jestExpect(received).not.toHaveLength(length);
     expect(() =>
       jestExpect(received).toHaveLength(
         length,
       )).toThrowErrorMatchingSnapshot();
   });
 });
Example #30
0
  [false, 1, 'a', undefined, null, {}, []].forEach(v => {
    it(`fails for '${stringify(v)}' with '.not'`, () => {
      let error;

      try {
        jestExpect(v).not.toBe(v);
      } catch (e) {
        error = e;
      }
      expect(error).toBeDefined();
      expect(error.message).toMatchSnapshot();
    });
  });