add passing unit test

This commit is contained in:
Luke Schlangen 2018-02-07 17:49:18 -06:00
parent f8dced53dc
commit 45cf1f685d
2 changed files with 16 additions and 7 deletions

View file

@ -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) {

View file

@ -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);
});