From f8dced53dc1a9c8e00a3224481bdb05578862f41 Mon Sep 17 00:00:00 2001 From: Luke Schlangen Date: Wed, 31 Jan 2018 08:23:08 -0600 Subject: [PATCH 1/2] round numbers but break tests --- src/blocks/scratch3_looks.js | 4 ++++ test/unit/blocks_looks.js | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/blocks/scratch3_looks.js b/src/blocks/scratch3_looks.js index e173ca04d..e011858ac 100644 --- a/src/blocks/scratch3_looks.js +++ b/src/blocks/scratch3_looks.js @@ -251,6 +251,10 @@ class Scratch3LooksBlocks { say (args, util) { // @TODO in 2.0 calling say/think resets the right/left bias of the bubble + let message = args.MESSAGE; + if (typeof message === 'number') { + message = message.toFixed(2); + } this._updateBubble(util.target, 'say', String(args.MESSAGE)); } diff --git a/test/unit/blocks_looks.js b/test/unit/blocks_looks.js index 1506d7f84..647aeb17a 100644 --- a/test/unit/blocks_looks.js +++ b/test/unit/blocks_looks.js @@ -50,3 +50,13 @@ test('getBackdropNumberName can return costume name', t => { t.strictEqual(number, 'third name'); t.end(); }); + +test('numbers should be rounded to two decimals in say', t => { + const args = {MESSAGE: 3.14159}; + const sayString = blocks.say(args, util); + // This breaks becuase it is not returned, + // instead this calls this._updateBubble(util.target, 'say', String(args.MESSAGE)); + // I'm not familiar + t.strictEqual(sayString, '3.14'); + t.end(); +}); From 45cf1f685df0eb4b19795bc2cacd6953d89ebfd9 Mon Sep 17 00:00:00 2001 From: Luke Schlangen Date: Wed, 7 Feb 2018 17:49:18 -0600 Subject: [PATCH 2/2] add passing unit test --- src/blocks/scratch3_looks.js | 3 ++- test/unit/blocks_looks.js | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/blocks/scratch3_looks.js b/src/blocks/scratch3_looks.js index e011858ac..8c17bb1b0 100644 --- a/src/blocks/scratch3_looks.js +++ b/src/blocks/scratch3_looks.js @@ -255,7 +255,8 @@ class Scratch3LooksBlocks { if (typeof message === 'number') { message = message.toFixed(2); } - this._updateBubble(util.target, 'say', String(args.MESSAGE)); + message = String(message); + this.runtime.emit('SAY', util.target, 'say', message); } sayforsecs (args, util) { diff --git a/test/unit/blocks_looks.js b/test/unit/blocks_looks.js index 647aeb17a..6c1877c8a 100644 --- a/test/unit/blocks_looks.js +++ b/test/unit/blocks_looks.js @@ -1,5 +1,6 @@ const test = require('tap').test; const Looks = require('../../src/blocks/scratch3_looks'); +const Runtime = require('../../src/engine/runtime'); const util = { target: { currentCostume: 0, // Internally, current costume is 0 indexed @@ -52,11 +53,18 @@ test('getBackdropNumberName can return costume name', t => { }); test('numbers should be rounded to two decimals in say', t => { + const rt = new Runtime(); + const looks = new Looks(rt); + const args = {MESSAGE: 3.14159}; - const sayString = blocks.say(args, util); - // This breaks becuase it is not returned, - // instead this calls this._updateBubble(util.target, 'say', String(args.MESSAGE)); - // I'm not familiar - t.strictEqual(sayString, '3.14'); - t.end(); + const expectedSayString = '3.14'; + + rt.removeAllListeners('SAY'); // Prevent say blocks from executing + + rt.addListener('SAY', (target, type, sayString) => { + t.strictEqual(sayString, expectedSayString); + t.end(); + }); + + looks.say(args, util); });