Leon Gaban
Leon Gaban

Reputation: 39018

TypeError (Jest Test) why would this test fail? Error says function is not a function

TypeError: (0 , _validators.validateEmail)(...).toBe is not a function

Is the error

Here is my test

// Utils
import { validateEmail, validatePassord } from './validators';

describe('validating email addresses', () => {
  it('should return true with a valid email', () => {
    expect(validateEmail('[email protected]').toBe(true));
  });

  it('should return false with an invalid email', () => {
    expect(validateEmail('badEmail').toBe(false));
  });
});

The utility it's testing

export const validateEmail = email => /@google.com\s*$/.test(email);

export const validatePassord = (password) => {
  const hasSpecial = /[!]+/.test(password);
  const hasAlpha = /[a-zA-Z]+/.test(password);
  const hasUppercase = /(?=.*[A-Z])+/.test(password);
  const hasNumber = /[0-9]+/.test(password);
  const hasMinChars = password.length >= 8;

  return hasSpecial && hasAlpha && hasUppercase && hasNumber && hasMinChars;
};

They are in the same directory. Error output:

enter image description here

Upvotes: 3

Views: 1047

Answers (1)

Kulix
Kulix

Reputation: 474

Try moving your parens around to something like...

expect(validateEmail('[email protected]')).toBe(true);

or something like this for the second test

expect(validateEmail('badEmail')).toBe(false);

Upvotes: 1

Related Questions