mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
Use captureWarning helper from dev-tools instead of mocha/test_helpers.js implementation.
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
"assertVariableValues": true,
|
||||
"assertNoWarnings": true,
|
||||
"assertWarnings": true,
|
||||
"captureWarnings": true,
|
||||
"captureWarnings": false,
|
||||
"createDeprecationWarningStub": true,
|
||||
"createKeyDownEvent": true,
|
||||
"createRenderedBlock": true,
|
||||
|
||||
@@ -85,7 +85,7 @@ suite('Registry', function() {
|
||||
test('Incorrect Plugin Name', function() {
|
||||
this.options['plugins']['test'] = 'random';
|
||||
var testClass;
|
||||
var warnings = captureWarnings(() => {
|
||||
var warnings = testHelpers.captureWarnings(() => {
|
||||
testClass = Blockly.registry.getClassFromOptions('test', this.options);
|
||||
});
|
||||
chai.assert.isNull(testClass);
|
||||
|
||||
@@ -20,25 +20,6 @@ function assertVariableValues(container, name, type, id) {
|
||||
chai.assert.equal(variable.getId(), id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures the strings sent to console.warn() when calling a function.
|
||||
* @param {function} innerFunc The function where warnings may called.
|
||||
* @return {string[]} The warning messages (only the first arguments).
|
||||
*/
|
||||
function captureWarnings(innerFunc) {
|
||||
var msgs = [];
|
||||
var nativeConsoleWarn = console.warn;
|
||||
try {
|
||||
console.warn = function(msg) {
|
||||
msgs.push(msg);
|
||||
};
|
||||
innerFunc();
|
||||
} finally {
|
||||
console.warn = nativeConsoleWarn;
|
||||
}
|
||||
return msgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given function logs the provided warning messages.
|
||||
* @param {function} innerFunc The function to call.
|
||||
@@ -49,7 +30,7 @@ function assertWarnings(innerFunc, messages) {
|
||||
if (!Array.isArray(messages)) {
|
||||
messages = [messages];
|
||||
}
|
||||
var warnings = captureWarnings(innerFunc);
|
||||
var warnings = testHelpers.captureWarnings(innerFunc);
|
||||
chai.assert.lengthOf(warnings, messages.length);
|
||||
messages.forEach((message, i) => {
|
||||
chai.assert.match(warnings[i], message);
|
||||
|
||||
@@ -1303,7 +1303,7 @@ function testAWorkspace() {
|
||||
this.workspace.createVariable('name1', 'type1', 'id1');
|
||||
this.workspace.deleteVariableById('id1');
|
||||
var workspace = this.workspace;
|
||||
var warnings = captureWarnings(function() {
|
||||
var warnings = testHelpers.captureWarnings(function() {
|
||||
workspace.deleteVariableById('id1');
|
||||
});
|
||||
chai.assert.equal(warnings.length, 1,
|
||||
@@ -1332,7 +1332,7 @@ function testAWorkspace() {
|
||||
createVarBlocksNoEvents(this.workspace, ['id1']);
|
||||
this.workspace.deleteVariableById('id1');
|
||||
var workspace = this.workspace;
|
||||
var warnings = captureWarnings(function() {
|
||||
var warnings = testHelpers.captureWarnings(function() {
|
||||
workspace.deleteVariableById('id1');
|
||||
});
|
||||
chai.assert.equal(warnings.length, 1,
|
||||
|
||||
Reference in New Issue
Block a user