Refactored the function createSpyForPluginEvent in the test suite