mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 06:23:37 -05:00
Implement a few tests for io/deviceManager
This commit is contained in:
parent
f3c6be2881
commit
9a9c509e76
2 changed files with 50 additions and 1 deletions
|
@ -161,7 +161,10 @@ class DeviceFinder {
|
|||
_getList () {
|
||||
this._deviceManager
|
||||
.list(this._extensionName, this._deviceType, this._deviceSpec)
|
||||
.then(listResult => this._listResultHandler(listResult));
|
||||
.then(
|
||||
listResult => this._listResultHandler(listResult),
|
||||
() => this._listResultHandler(null)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
46
test/unit/io_deviceManager.js
Normal file
46
test/unit/io_deviceManager.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
const test = require('tap').test;
|
||||
const DeviceManager = require('../../src/io/deviceManager');
|
||||
|
||||
test('spec', t => {
|
||||
const deviceManager = new DeviceManager();
|
||||
|
||||
t.type(DeviceManager, 'function');
|
||||
t.type(deviceManager, 'object');
|
||||
t.type(deviceManager.list, 'function');
|
||||
t.type(deviceManager.open, 'function');
|
||||
t.type(deviceManager.searchAndConnect, 'function');
|
||||
t.type(deviceManager.isConnected, 'boolean');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('default connected', t => {
|
||||
const deviceManager = new DeviceManager();
|
||||
|
||||
t.strictEqual(deviceManager.isConnected, true);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cancel searchAndConnect', t => {
|
||||
const deviceManager = new DeviceManager();
|
||||
|
||||
const finder = deviceManager.searchAndConnect('test extension', 'test device');
|
||||
|
||||
let resolved = false;
|
||||
let rejected = false;
|
||||
const testPromise = finder.promise
|
||||
.then(
|
||||
() => {
|
||||
resolved = true;
|
||||
},
|
||||
() => {
|
||||
rejected = true;
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
t.strictEqual(resolved, false);
|
||||
t.strictEqual(rejected, true);
|
||||
});
|
||||
finder.cancel();
|
||||
|
||||
return testPromise;
|
||||
});
|
Loading…
Reference in a new issue