diff --git a/tests/mocha/.eslintrc.json b/tests/mocha/.eslintrc.json index cbd03a1ff..bb10deb57 100644 --- a/tests/mocha/.eslintrc.json +++ b/tests/mocha/.eslintrc.json @@ -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, diff --git a/tests/mocha/comment_test.js b/tests/mocha/comment_test.js index e026fdfd4..af61c35ec 100644 --- a/tests/mocha/comment_test.js +++ b/tests/mocha/comment_test.js @@ -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) { diff --git a/tests/mocha/connection_test.js b/tests/mocha/connection_test.js index da933a404..48bee2513 100644 --- a/tests/mocha/connection_test.js +++ b/tests/mocha/connection_test.js @@ -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'); }); }); diff --git a/tests/mocha/field_image_test.js b/tests/mocha/field_image_test.js index 0ef8055f7..bcdae8999 100644 --- a/tests/mocha/field_image_test.js +++ b/tests/mocha/field_image_test.js @@ -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() { diff --git a/tests/mocha/test_helpers.js b/tests/mocha/test_helpers.js index 69f9a0261..922f13b14 100644 --- a/tests/mocha/test_helpers.js +++ b/tests/mocha/test_helpers.js @@ -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