Answer the question
In order to leave comments, you need to log in
How to test an already written site?
I am writing a website. Typical online store. Adding a product, mini cart and shopping cart. Without any fraimworks. Stupidly native. All in one file. In general, as a real work developed XD. At a certain point, everything works, but the client wants to slightly expand and change the functionality. I add a couple of functions and ... nothing works. Well, that is, part works, part works, part works wrong or not there. Before that, tests were not written and I have no idea how they are written at all. And they tell me - I had to write tests for my JS to see what works and what doesn't. And the question is - how can this be done already on a working site? All files on the server, the database is there. I looked - it was necessary to write with one of the BDD or TDD methodologies. And use various fraimworks for this. mocha for description, jusmine or chai for tests, karma for running tests in the console. Okay, but how do I attach all this to the site and my functions? There is a class, it is initialized if, for example, there is a certain class on the page.
function Class(){
tihs._data = {
text: 'Нажал'
}
this.init();
}
Class.prototype.init = function(){
var btns = document.querySelectorAll('.btns');
if(!!btns.length){
for(var i = 0; i < btns.length; i++){
btns[i].onclick = this.btn_click();
}
}
}
Class.prototype.btn_click = function(){
return function(ev){
console.info(this._data.text);
}.bind(this)
}
Answer the question
In order to leave comments, you need to log in
Tests can be run with ANY code.
The algorithm is simple: action->result->comparison of expectation and result->conclusion.
I advise Nightmare to nightmare ..... ( www.nightmarejs.org )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question