Skip to content

Commit

Permalink
wip, struggling with fancy mocking
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Gustafson <[email protected]>

JerryScript-DCO-1.0-Signed-off-by: Geoff Gustafson [email protected]
  • Loading branch information
grgustaf committed Mar 2, 2018
1 parent 23ae7b2 commit 67231f0
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions jerry-debugger/src/lib/__tests__/debugger-client.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright JS Foundation and other contributors, http://js.foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { JerryDebugger, DEFAULT_DEBUGGER_HOST, DEFAULT_DEBUGGER_PORT } from '../debugger-client';
import WebSocket from 'ws';

//const mockOn = jest.fn();
jest.mock('ws', () => {
return jest.fn().mockImplementation(() => {
return {};
});
});

describe('JerryDebugger constructor', () => {
it ('uses supplied option values', () => {
const jd = new JerryDebugger({
host: '10.10.10.10',
port: 4096,
verbose: true,
});
expect(jd.host).toEqual('10.10.10.10');
expect(jd.port).toEqual(4096);
expect(jd.verbose).toEqual(true);
});

it('supplies option defaults when missing', () => {
const jd = new JerryDebugger({});
expect(jd.host).toEqual(DEFAULT_DEBUGGER_HOST);
expect(jd.port).toEqual(DEFAULT_DEBUGGER_PORT);
expect(jd.verbose).toEqual(false);
});
});

describe('JerryDebugger.connect', () => {
beforeEach(() => {
});

it('creates a websocket', () => {
const jd = new JerryDebugger({});
jd.connect();
expect(WebSocket).toHaveBeenCalledTimes(1);
});

it('returns a resolving promise when already connected', () => {
const jd = new JerryDebugger({});
jd.connect();
expect(WebSocket).toHaveBeenCalledTimes(1);
const p2 = jd.connect();
console.log('here1');
return expect(p2).resolves.toBe(undefined);
});

it('returned promise resolves when socket connects', () => {
const jd = new JerryDebugger({});
const p = jd.connect();
console.log('here2');
expect(p).resolves.toBe(undefined);
});
});

0 comments on commit 67231f0

Please sign in to comment.