Add test for skipping rename on blank input

This commit is contained in:
Paul Kaplan 2017-03-20 11:14:25 -04:00
parent 627fc1d9c3
commit 5d2352e471
2 changed files with 15 additions and 1 deletions

View file

@ -204,7 +204,9 @@ VirtualMachine.prototype.renameSprite = function (targetId, newName) {
if (!sprite) {
throw new Error('No sprite associated with this target.');
}
sprite.name = newName;
if (newName) {
sprite.name = newName;
}
this.emitTargetsUpdate();
} else {
throw new Error('No target with the provided id.');

View file

@ -49,3 +49,15 @@ test('renameSprite sets the sprite name', function (t) {
t.equal(fakeTarget.sprite.name, 'not-original');
t.end();
});
test('renameSprite does not set sprite names to an empty string ', function (t) {
var vm = new VirtualMachine();
var fakeTarget = {
sprite: {name: 'original'},
isSprite: () => true
};
vm.runtime.getTargetById = () => (fakeTarget);
vm.renameSprite('id', '');
t.equal(fakeTarget.sprite.name, 'original');
t.end();
});