0

I've looked at previous articles but they seem to be updated, and I've hit a brick wall. Can anyone help me find a solution?

I've got a directive that has some events bind. It's a credit card number filter, so it adds a space every 4 numbers to make it easier to read. I'm trying to test it in karma/jasmine by feeding it the number 5555555555554444, and expect response for $viewValue of 5555 5555 5555 4444, but can't find a way to trigger the event to fire.

I've tried $setViewValue, $render(), $digest(), and I've tried some of the solutions from StackOverflow (over a year old) but they don't seem to work.

Is the only solution to use jQuery? And if so, does that jQuery solution still work? I've been trying to do this without including jQuery into my unit tests.

A code sample of what I'm working with:

    elem.bind('keypress', parseKeyPress);
    elem.bind('keydown contextmenu', parseKeyDown);
    elem.bind('cut paste', parseCutPaste);

    var parseHandler= function (value) {
      return value ? returnNumbersOnly(value) : '';
    };
    ctrl.$parsers.unshift(parseHandler);
    ctrl.$formatters.unshift(parseHandler);

Thoughts?

1

1 Answer 1

1

You should use elem.trigger(...) to emit those events as needed.

1
  • @BuildTester1 you can create a one with angular.element Jan 20, 2015 at 2:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.