Handle testing deprecated methods. (#4195)

* Handle testing deprecated methods.
This commit is contained in:
Monica Kozbial
2020-08-19 17:53:49 -07:00
committed by GitHub
parent ab474c8966
commit 49e0ff4318
5 changed files with 54 additions and 5 deletions

View File

@@ -8,12 +8,15 @@
"chai": false,
"sinon": false,
"assertArrayEquals": true,
"assertDeprecationWarningCall": true,
"assertEventEquals": true,
"assertEventFired": true,
"assertEventNotFired": true,
"assertNthCallEventArgEquals": true,
"assertSingleDeprecationWarningCall": true,
"assertVariableValues": true,
"captureWarnings": true,
"createDeprecationWarningStub": true,
"createRenderedBlock": true,
"createTestBlock": true,
"defineBasicBlockWithField": true,

View File

@@ -31,7 +31,7 @@ suite('Comments', function() {
});
suite('Visibility and Editability', function() {
setup(function() {
this.comment.setText('test text');
this.block.setCommentText('test text');
});
function assertEditable(comment) {

View File

@@ -21,30 +21,42 @@ suite('Connection', function() {
teardown(function() {
sharedTestTeardown.call(this);
});
test('canConnectWithReason passes', function() {
test('Deprecated - canConnectWithReason passes', function() {
var deprecateWarnSpy = createDeprecationWarningStub();
var conn1 = this.createConnection(Blockly.PREVIOUS_STATEMENT);
var conn2 = this.createConnection(Blockly.NEXT_STATEMENT);
chai.assert.equal(conn1.canConnectWithReason(conn2),
Blockly.Connection.CAN_CONNECT);
assertSingleDeprecationWarningCall(deprecateWarnSpy,
'Connection.prototype.canConnectWithReason');
});
test('canConnectWithReason fails', function() {
test('Deprecated - canConnectWithReason fails', function() {
var deprecateWarnSpy = createDeprecationWarningStub();
var conn1 = this.createConnection(Blockly.PREVIOUS_STATEMENT);
var conn2 = this.createConnection(Blockly.OUTPUT_VALUE);
chai.assert.equal(conn1.canConnectWithReason(conn2),
Blockly.Connection.REASON_WRONG_TYPE);
assertSingleDeprecationWarningCall(deprecateWarnSpy,
'Connection.prototype.canConnectWithReason');
});
test('checkConnection passes', function() {
test('Deprecated - checkConnection passes', function() {
var deprecateWarnSpy = createDeprecationWarningStub();
var conn1 = this.createConnection(Blockly.PREVIOUS_STATEMENT);
var conn2 = this.createConnection(Blockly.NEXT_STATEMENT);
chai.assert.doesNotThrow(function() {
conn1.checkConnection(conn2);
});
assertSingleDeprecationWarningCall(deprecateWarnSpy,
'Connection.prototype.checkConnection');
});
test('checkConnection fails', function() {
test('Deprecated - checkConnection fails', function() {
var deprecateWarnSpy = createDeprecationWarningStub();
var conn1 = this.createConnection(Blockly.PREVIOUS_STATEMENT);
var conn2 = this.createConnection(Blockly.OUTPUT_VALUE);
chai.assert.throws(function() {
conn1.checkConnection(conn2);
});
assertSingleDeprecationWarningCall(deprecateWarnSpy,
'Connection.prototype.checkConnection');
});
});

View File

@@ -157,10 +157,13 @@ suite('Image Fields', function() {
chai.assert.equal(field.altText_, 'alt');
});
test('Deprecated - setText', function() {
var deprecateWarnSpy = createDeprecationWarningStub();
var field = new Blockly.FieldImage('src', 10, 10, 'alt');
chai.assert.throws(function() {
field.setText('newAlt');
});
assertSingleDeprecationWarningCall(deprecateWarnSpy,
'Field.prototype.setText');
});
suite('SetAlt', function() {
setup(function() {

View File

@@ -39,6 +39,37 @@ function captureWarnings(innerFunc) {
return msgs;
}
/**
* Stubs Blockly.utils.deprecation.warn call.
* @return {!SinonStub} The created stub.
*/
function createDeprecationWarningStub() {
return sinon.stub(Blockly.utils.deprecation, 'warn');
}
/**
* Asserts whether the given deprecation warning stub or call was called with
* the expected functionName.
* @param {!SinonSpy|!SinonSpyCall} spyOrSpyCall The spy or spy call to use.
* @param {string} functionName The function name to check that the given spy or
* spy call was called with.
*/
function assertDeprecationWarningCall(spyOrSpyCall, functionName) {
sinon.assert.calledWith(spyOrSpyCall, functionName);
}
/**
* Asserts that there was a single deprecation warning call with the given
* functionName passed.
* @param {!SinonSpy} spy The spy to use.
* @param {string} functionName The function name to check that the given spy
* was called with.
*/
function assertSingleDeprecationWarningCall(spy, functionName) {
sinon.assert.calledOnce(spy);
assertDeprecationWarningCall(spy.getCall(0), functionName);
}
/**
* Safely disposes of Blockly workspace, logging any errors.
* Assumes that sharedTestSetup has also been called. This should be called