I have a class A
which contains an instance of class B
, and function foo
of A
calls function set
of B
, which updates the state of B
. Here is a code example (in Javascript):
A = function () {
this.init = function (b) {
this.b = b
}
this.foo = function (val) {
this.b.set(val)
}
this.bar = function () {
return this.b.get()
}
}
B = function () {
this.set = function (val) {
this.v = val
}
this.get = function () {
return this.v
}
}
How do I unit-test the foo
function, while keeping the test for A
non-dependent on the implementation of B
(using mocks and stubs and what not)?