Skip to content
This repository has been archived by the owner on May 29, 2023. It is now read-only.

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
waterplea committed Feb 10, 2020
1 parent 5162af0 commit 1f00b1c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 33 deletions.
19 changes: 0 additions & 19 deletions projects/midi/src/test.ts
Expand Up @@ -10,25 +10,6 @@ import {

declare const require: any;

fetch('http://localhost:9222/json')
.then(response => response.json())
.then(response => {
const socket = new WebSocket(response[0].webSocketDebuggerUrl);

socket.onopen = () => {
socket.send(
JSON.stringify({
id: 1,
method: 'Browser.grantPermissions',
params: {
origin: 'http://localhost:9876',
permissions: ['midi', 'midiSysex'],
},
}),
);
};
});

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
Expand Down
39 changes: 25 additions & 14 deletions projects/midi/src/tokens/tests/midi-access.spec.ts
@@ -1,35 +1,46 @@
import {TestBed} from '@angular/core/testing';
import {NAVIGATOR} from '@ng-web-apis/common';
import {MIDI_ACCESS} from '../midi-access';
import {SYSEX} from '../sysex';

describe('MIDI_ACCESS', () => {
// TODO: Wait before remote debugging allows midi access
beforeAll(done => {
setTimeout(() => {
done();
}, 4000);
});
const navigatorMock = jasmine.createSpyObj(['requestMIDIAccess']);

it('SYSEX is false by default', () => {
TestBed.configureTestingModule({
providers: [
{
provide: NAVIGATOR,
useValue: navigatorMock,
},
],
});

TestBed.get(MIDI_ACCESS);

it('SYSEX is false by default', done => {
TestBed.get(MIDI_ACCESS).then((midiAccess: any) => {
expect(midiAccess.sysexEnabled).toBe(false);
done();
expect(navigatorMock.requestMIDIAccess.calls.mostRecent().args[0]).toEqual({
sysex: false,
});
});

it('SYSEX is set to true', done => {
it('SYSEX is set to true', () => {
TestBed.configureTestingModule({
providers: [
{
provide: NAVIGATOR,
useValue: navigatorMock,
},
{
provide: SYSEX,
useValue: true,
},
],
});

TestBed.get(MIDI_ACCESS).then((midiAccess: any) => {
expect(midiAccess.sysexEnabled).toBe(true);
done();
TestBed.get(MIDI_ACCESS);

expect(navigatorMock.requestMIDIAccess.calls.mostRecent().args[0]).toEqual({
sysex: true,
});
});
});

0 comments on commit 1f00b1c

Please sign in to comment.