I'm new to sinon and not entirely sure how it is meant to be implemented.
I am using it in a Qunit test to intercept a message displayed to the console.
I have a popup.js utility that calls console.log('Error!!!') when the popup'd message is missing.
In my popup.tests.js file I'm trying to do this:
QUnit.test('A warning message is logged to console when no message is provided to Popup', function (assert) {
delete config.message; // Remove the message from Popup config (message is required).
// openPopup();// Call the popup's open function. With no message, this will log to console
var stub = sinon.stub(Popup, "openPopup"); // the open method for Popup utility
var intercepted = stub.returns(Popup); // intercepted should contain "Error!!!"
});
My first problem is that there's no object in my test file called Popup. I don't know how to get a handle on it.
This is what I've tried:
var p = QUnit.module('Popup.js', {
...
});
then
QUnit.test('warning message logged', function (assert) {
var stub = sinon.stub(p, "openPopup");
var intercepted = stub.returns(p);
});
but I still get TypeError: Should wrap property of object