You can only record calls on function and check that tey was called, but never change the behavior of the function. From the doc for withArgs
:
Creates a spy that only records calls when the received arguments matche those passed to withArgs
Whar you are looking for is a sinon.stub
:
sinon.stub(document, 'getElementById').withArgs('foo').returns(['bar'])