mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 06:23:37 -05:00
Add tests for existing vm.renameSprite functionality
This commit is contained in:
parent
b03768cad6
commit
627fc1d9c3
1 changed files with 51 additions and 0 deletions
51
test/unit/virtual-machine.js
Normal file
51
test/unit/virtual-machine.js
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
var test = require('tap').test;
|
||||||
|
var VirtualMachine = require('../../src/virtual-machine.js');
|
||||||
|
|
||||||
|
test('renameSprite throws when there is no sprite with that id', function (t) {
|
||||||
|
var vm = new VirtualMachine();
|
||||||
|
vm.runtime.getTargetById = () => null;
|
||||||
|
t.throws(
|
||||||
|
(() => vm.renameSprite('id', 'name')),
|
||||||
|
new Error('No target with the provided id.')
|
||||||
|
);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('renameSprite throws when used on a non-sprite target', function (t) {
|
||||||
|
var vm = new VirtualMachine();
|
||||||
|
var fakeTarget = {
|
||||||
|
isSprite: () => false
|
||||||
|
};
|
||||||
|
vm.runtime.getTargetById = () => (fakeTarget);
|
||||||
|
t.throws(
|
||||||
|
(() => vm.renameSprite('id', 'name')),
|
||||||
|
new Error('Cannot rename non-sprite targets.')
|
||||||
|
);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('renameSprite throws when there is no sprite for given target', function (t) {
|
||||||
|
var vm = new VirtualMachine();
|
||||||
|
var fakeTarget = {
|
||||||
|
sprite: null,
|
||||||
|
isSprite: () => true
|
||||||
|
};
|
||||||
|
vm.runtime.getTargetById = () => (fakeTarget);
|
||||||
|
t.throws(
|
||||||
|
(() => vm.renameSprite('id', 'name')),
|
||||||
|
new Error('No sprite associated with this target.')
|
||||||
|
);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('renameSprite sets the sprite name', function (t) {
|
||||||
|
var vm = new VirtualMachine();
|
||||||
|
var fakeTarget = {
|
||||||
|
sprite: {name: 'original'},
|
||||||
|
isSprite: () => true
|
||||||
|
};
|
||||||
|
vm.runtime.getTargetById = () => (fakeTarget);
|
||||||
|
vm.renameSprite('id', 'not-original');
|
||||||
|
t.equal(fakeTarget.sprite.name, 'not-original');
|
||||||
|
t.end();
|
||||||
|
});
|
Loading…
Reference in a new issue