timhaley94/holdem

View on GitHub
server/src/testHelpers.js

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
function hasEqualIds(a, b) {
  const toString = (x) => {
    const id = x._id || x.id || x;
    return typeof id === 'string' ? id : id.toString();
  };

  return toString(a) === toString(b);
}

async function expectThrows(fn, err) {
  expect.hasAssertions();

  try {
    await fn();
  } catch (e) {
    expect(e instanceof err).toBe(true);
  }
}

function expectEqualIds(a, b) {
  expect(
    hasEqualIds(a, b),
  ).toEqual(true);
}

module.exports = {
  hasEqualIds,
  expectThrows,
  expectEqualIds,
};