Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions basic-tts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,43 @@
utils.checkCheckVoices(done, 1, data);
});
});

describe("normalizes attempts when", () => {
const data = [1, 2];

test("attempts is a numeric string", (done) => {
tts.enableTesting(utils.getMockWindowWithAttempts(2, data));

tts.checkVoices("2").then((result) => {
expect(result.voices).toEqual(data);
done();
}).catch((err) => {
done(new Error(`Unexpected error: ${JSON.stringify(err)}`));
});
});

test("attempts is a non-numeric string (resets to valid default)", (done) => {

Check failure on line 212 in basic-tts.test.js

View workflow job for this annotation

GitHub Actions / Lint

This line has a length of 86. Maximum allowed is 80

Check failure on line 212 in basic-tts.test.js

View workflow job for this annotation

GitHub Actions / Lint

This line has a length of 86. Maximum allowed is 80
tts.enableTesting(utils.getMockWindowWithAttempts(0, data));

tts.checkVoices("abc").then((result) => {
expect(result.voices).toEqual(data);
done();
}).catch((err) => {
done(new Error(`Unexpected error: ${JSON.stringify(err)}`));
});
});

test("attempts is negative (resets to valid default)", (done) => {
tts.enableTesting(utils.getMockWindowWithAttempts(0, data));

tts.checkVoices(-1).then((result) => {
expect(result.voices).toEqual(data);
done();
}).catch((err) => {
done(new Error(`Unexpected error: ${JSON.stringify(err)}`));
});
});
});
});

describe("createSpeaker", () => {
Expand Down Expand Up @@ -323,6 +360,17 @@
expectSpeakToFail(speaker, text, expected, done);
});

test("voice is invalid", (done) => {
tts.enableTesting(utils.getMockWindowWithVoices(...names));

const speaker = tts.createSpeaker({voice: "baz"});
const expected = {
msg: "Speech could not be initialized due to invalid voice"
};

expectSpeakToFail(speaker, text, expected, done);
});

test("speaking produced unknown error", (done) => {
const mockWindow = utils.getMockWindowWithVoices(...names);
mockWindow.speechSynthesis.speak = (utterance) => {
Expand Down Expand Up @@ -361,3 +409,55 @@
});
});
});

describe("AMD define", () => {
let originalDefine;

beforeEach(() => {
originalDefine = global.define;
jest.resetModules();
});

afterEach(() => {
if (originalDefine === undefined) {
delete global.define;
} else {
global.define = originalDefine;
}
});

test("calls define when AMD is available", () => {
const calls = [];
global.define = (...args) => { calls.push(args); };
global.define.amd = true;

require("./basic-tts");

expect(calls.length).toBe(2);
expect(calls[0][0]).toBe("basic-tts");
expect(calls[0][1]).toEqual([]);
expect(typeof calls[0][2]).toBe("function");
expect(calls[1][0]).toEqual([]);
expect(typeof calls[1][1]).toBe("function");
});

test("factory functions return the tts module", () => {
const calls = [];
global.define = (...args) => { calls.push(args); };
global.define.amd = true;

const freshTts = require("./basic-tts");

expect(calls[0][2]()).toBe(freshTts);
expect(calls[1][1]()).toBe(freshTts);
});

test("does not call define when AMD is not available", () => {
let called = false;
global.define = () => { called = true; };

require("./basic-tts");

expect(called).toBe(false);
});
});
Loading