Run Javascript unit tests to test user input code in the application at run time

In many code learning sites, the application is able to test the code entered by user. Ex: freecodecamp.org runs unit tests to check if user has entered correct code. I am trying to get the same feature using angular as front end. I know that we can run tests from CLI using karma, but i want to run these tests when user inputs the code and show him if he as entered the expected code. I want to know how can it be done within the application.