Share your repls and programming experiences

← Back to all posts
A Unit Testing library for DOM
AndrewAung11

About

This is a testing library for HTML\CSS\JS projects.
I used Javascript minifier for utd.min.js


Importing

Hae Hae ^_^

I don't know how to get file link in replit.
So just copy and paste the js code to your project.
You can see it in my example page too.

I have got an idea too.
Here the link of the script file that I get from the example page: https://testing-utd.andrewaung11.repl.co/utd.min.js
That link will be working until I haven't deleted the example project.


How to use

There are four functions:

  • constructor
  • checkHTML
  • checkText
  • checkAttr
  • emitEvent

constructor

It is easy. First you need to select one html element. Then create an instance of Test class:

The constructor take only one argument which is for the target.

checkHTML

As the function is named check HTML it take in one argument the expected value for the innerHTML of the target. If the innerHTML value of the target is equals to the expected value then the function will return Passed if not it will return Not Passed. Here, example:

checkText

This function work same as the checkHTML function. But this function check textContent instead of innerHTML. Here, the example:

checkAttr

This function take two arguments first is the attribute name. And the second one is attribute's value. It firstly check if the passed in attribute is defined. If it isn't then return "No attribute with name ${attr}". Or if it is defined, it check for the value that if it is equals to the expected value. Here, the example:

emitEevent

This function emit an event to the target (like: click, mouseover). Be careful about event names because the function create a new Event object so spelling wrong or passing invalid event name will cause an error. And for the arguments it take in two. One for event and one for the function that will execute after emitting. And for the passed in function it pass 2 arguments when executing; the target's innerHTML and textContent. Here an example:


Bye Bye

That is all that I have written.
Here live example: Testing UTD

Voters
ANDREWVOSS
DynamicSquid
ch1ck3n
AndrewAung11
Comments
hotnewtop
DynamicSquid

Cool!

ch1ck3n

noice