mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-13 06:49:19 -04:00
Adding unit tests for new lookupOrCreate funciton, fixing a bug that came up during testing (using lookupVariableById on a null target). Skipping integration tests that do not work right now because SB2 import of broadcast message blocks has not been implemented yet.
This commit is contained in:
parent
b674a0c047
commit
e5378d323d
6 changed files with 54 additions and 10 deletions
test/unit
|
@ -173,3 +173,32 @@ test('lookupOrCreateList returns list if one with given id exists', t => {
|
|||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('lookupOrCreateBroadcastMsg creates a var if one does not exist', t => {
|
||||
const target = new Target();
|
||||
const variables = target.variables;
|
||||
|
||||
t.equal(Object.keys(variables).length, 0);
|
||||
const broadcastVar = target.lookupOrCreateBroadcastMsg('foo', 'bar');
|
||||
t.equal(Object.keys(variables).length, 1);
|
||||
t.equal(broadcastVar.id, 'foo');
|
||||
t.equal(broadcastVar.name, 'bar');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('lookupOrCreateBroadcastMsg returns the var with given id if exists', t => {
|
||||
const target = new Target();
|
||||
const variables = target.variables;
|
||||
|
||||
t.equal(Object.keys(variables).length, 0);
|
||||
target.createVariable('foo', 'bar', Variable.BROADCAST_MESSAGE_TYPE);
|
||||
t.equal(Object.keys(variables).length, 1);
|
||||
|
||||
const broadcastMsg = target.lookupOrCreateBroadcastMsg('foo', 'bar');
|
||||
t.equal(Object.keys(variables).length, 1);
|
||||
t.equal(broadcastMsg.id, 'foo');
|
||||
t.equal(broadcastMsg.name, 'bar');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue