Currently leveraging sinon.js for stubbing functionalities where it is feasible to stub and spy on methods but not properties based on my observations.
I'm interested in knowing if there's a way to verify whether state.searchText
gets assigned the value of state.suggestion
prior to invoking submit
in the given example:
// utilizing angular at present, though relevant for vanilla js as well
$scope.searchSuggestion = function() {
this.state.searchText = this.state.suggestion;
this.submit();
};
Optimal testing snippet would be:
it('should set the searchText to be the suggestion', function(){
// arrange
sinon.stub(scope, 'submit');
scope.state.searchText = 'old value';
scope.state.suggestion = 'new value';
// act
scope.searchSuggestion();
// assert
expect(scope.submit.called).to.be(true)
// ~uncertain about verifying searchText being set first
});