@jest/globals#expect TypeScript Examples

The following examples show how to use @jest/globals#expect. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: main.test.ts    From gh-get-current-pr with GNU General Public License v3.0 6 votes vote down vote up
test('prefers PR with commit as head SHA', () => {
  const testPRs = [
    createDummyPR(1, {sha: '09e30775c'}),
    createDummyPR(2, {sha: '90775cae3'})
  ]
  const options = {
    preferWithHeadSha: testPRs[1].head.sha
  }
  const foundPR = getLastPullRequest(testPRs, options) || {id: null}
  expect(foundPR.id).toBe(testPRs[1].id)
})
Example #2
Source File: get-default.spec.ts    From leapp with Mozilla Public License 2.0 6 votes vote down vote up
describe("GetDefaultRegion", () => {
  test("run", async () => {
    const cliProviderService = { regionsService: { getDefaultAwsRegion: () => "defaultRegion" } } as any;

    const command = new GetDefaultRegion([], {} as any);
    (command as any).cliProviderService = cliProviderService;
    command.log = jest.fn();

    await command.run();

    expect(command.log).toHaveBeenCalledWith("defaultRegion");
  });
});
Example #3
Source File: capitalize.test.ts    From vkui-tokens with MIT License 6 votes vote down vote up
describe('capitalize', () => {
	it('should work without letters', () => {
		expect(capitalize('')).toBe('');
	});
	it('should work with 1 letter', () => {
		expect(capitalize('a')).toBe('A');
	});

	it('should work with some letters', () => {
		expect(capitalize('aaaaa')).toBe('Aaaaa');
	});

	it('should ignore another letters', () => {
		expect(capitalize('1ds')).toBe('1ds');
	});
});
Example #4
Source File: errors.ts    From blockfrost-js with Apache License 2.0 6 votes vote down vote up
// eslint-disable-next-line @typescript-eslint/no-var-requires

describe('errors', () => {
  fixtures.handleError.forEach(f => {
    test(`handleError: ${f.description}`, async () => {
      // Set up the mock request.
      const scope = nock('http://localhost');

      if (f.payload.code === 'ETIMEDOUT') {
        scope.get('/test').delayConnection(1000).reply(200);
      } else {
        scope
          .get('/test')
          .reply(f.payload.response.statusCode, f.payload.response.body);
      }
      await got('http://localhost/test', {
        retry: 0,
        timeout: {
          lookup: 100,
          connect: 50,
          secureConnect: 50,
          socket: 1000,
          send: 10000,
          response: f.payload.code === 'ETIMEDOUT' ? 1 : 1000,
        },
      }).catch(err => {
        const handledError = handleError(err);
        const serializedError = serializeError(handledError);
        expect(handledError).toBeInstanceOf(Error);
        expect(serializedError).toMatchObject(f.result);
      });

      // Assert that the expected request was made.
      scope.done();
    });
  });
});
Example #5
Source File: array.test.ts    From zod with MIT License 6 votes vote down vote up
test("failing validations", () => {
  expect(() => minTwo.parse(["a"])).toThrow();
  expect(() => maxTwo.parse(["a", "a", "a"])).toThrow();
  expect(() => justTwo.parse(["a"])).toThrow();
  expect(() => justTwo.parse(["a", "a", "a"])).toThrow();
  expect(() => intNum.parse([])).toThrow();
  expect(() => nonEmptyMax.parse([])).toThrow();
  expect(() => nonEmptyMax.parse(["a", "a", "a"])).toThrow();
});