using spy to test statechange event