Testing segments API

- adding sinon for stubs
- minor tweaks, like `==` -> `===` or parenting an anonymous function