Answer the question
In order to leave comments, you need to log in
Proper Javascript testing?
Hello! I wanted to learn more about testing in Javascript. I use mocha + chai. I'm running through gulp. And I would like to understand in more detail the types of tests:
Do unit tests assume dependence on other classes. That is, we will import a class into the test that will import other classes into itself? Is it possible to work with DOM in an imported class? Would this be considered a unit test? What then does an integration test include? Help, please, deal with the issue. Thank you all in advance!
Answer the question
In order to leave comments, you need to log in
That is, we will import a class into the test that will import other classes into itself?
// A.js
class A {}
export const a = new A();
// B.js
import { a } from './A';
export class B {
constructor() {
this.a = a;
}
doStuff() {}
};
// A.js
export class A {};
// B.js
export class B {
constructor(a) {
this.a = a;
}
doStuff() {}
};
// index.js
import { A } from './A';
import { B } from './B';
const a = new A();
const b = new B(a);
b.doStuff();
If an object instantiates another object within itself, then such an object should be considered as a single unit.
import LineItem from './LineItem';
class Order {
constructor(lineItems = []) {
this.lineItems = lineItems;
}
addLineItem(name, cost, quantity) {
this.lineItems.push(new LineItem(name, cost, quantity));
}
}
class Route {...}
class Ship {
addRoute(route) {
if (!(route instanceof Route)) {
throw new Error('route must be instance of Route');
}
this.route = route;
}
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question