I am reading the book TDD by Example and one of the patterns demonstrated was the self-shunt pattern.
Basically, if I am not mistaken, if I have a test like this:
test("list of users should receive a new user"), () => {
const user = new User()
const listOfUsers = new ListOfUsers()
listOfUsers.insert(user)
}
Then, the only way to know if listOfUsers
actually received the user, is to stub it, correct?
class ListOfUsersStub {
constructor () {
this.users = []
}
insert (user) {
this.users.push(user)
return this.users
}
}
then I can test it so:
test("list of users should receive a new user"), () => {
const user = new User()
const listOfUsers = new ListOfUsers()
const result = listOfUsers.insert(user)
expect(result.users).toContain(user)
}
Is this the same as the self shunt pattern? Or am I missing something?
Thanks
Go to Source
Author: kibe