Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New/user static tests #1

Open
wants to merge 7 commits into
base: development
Choose a base branch
from
Open

Conversation

the-vampiire
Copy link

@the-vampiire the-vampiire commented Jan 28, 2019

Completed all tests for:

  • hashPassword()
  • verifyPassword()
  • verifyAndHashPassword()
  • register()

Simplified register() tests using method spies instead of mocks. We don't care what the method returns so much as we care that the User.create() Sequelize method was called with the correct inputs. Function/method spies provide us with this verification. See the changed tests for a better understanding of spying / the refactor.

created a testError() utility (in test_utils/) for testing thrown errors. there was too much duplicated and tedious code when testing the thrown errors.

/**
 * Tests the existence and shape of a thrown Error
 * @param {object} options Options to test for
 * @param {Error} options.error The Error object to test
 * @param {string} options.errorType The Type of Error (constructor name)
 * @param {string} options.message The expected Error message
 * @param {[string]} options.invalidArgs An Array of invalid arguments [Apollo Errors only]
 */
function testError(options) {
  const { error, errorType = "Error", message, invalidArgs } = options;

  expect(error).toBeDefined();
  expect(error.constructor.name).toBe(errorType);
  expect(error.message).toBe(message);
  if (invalidArgs) {
    expect(error.invalidArgs).toEqual(expect.arrayContaining(invalidArgs));
  }
}

@the-vampiire
Copy link
Author

I tried fucking everything and no matter what the JSDocs on testError() do not carry over. What is the point of writing them if they don't show up when you go to import and use the function...

I don't fucking get it. Now I remember why I stopped writing them. So frustrating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant