Skip to content

Commit 910121e

Browse files
committed
add: speakFn tests
1 parent 1f74ca9 commit 910121e

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

tests/lib/speechSynthesis.spec.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { describe, it } from 'mocha';
1+
import { describe, it, afterEach, beforeEach } from 'mocha';
22
import { expect } from 'chai';
3+
import { spy } from 'sinon';
4+
35
import { getSpeakText, speakFn } from '../../lib/speechSynthesis';
46

57
describe('SpeechSynthesis', () => {
@@ -25,4 +27,44 @@ describe('SpeechSynthesis', () => {
2527
expect(text).to.eql('');
2628
});
2729
});
30+
describe('speak', () => {
31+
const speakSpy = spy();
32+
33+
beforeEach(() => {
34+
global.window.speechSynthesis = {
35+
speak: speakSpy,
36+
};
37+
global.window.SpeechSynthesisUtterance = function SpeechSynthesisUtterance() {};
38+
});
39+
afterEach(() => {
40+
speakSpy.reset();
41+
});
42+
it('should not speak if disabled', () => {
43+
const speak = speakFn({ enable: false });
44+
speak({});
45+
expect(speakSpy.called).to.eql(false);
46+
});
47+
it('should not speak if SpeechSynthesisUtterance is not supported', () => {
48+
global.window.SpeechSynthesisUtterance = undefined;
49+
const speak = speakFn({ enable: true });
50+
speak({});
51+
expect(speakSpy.called).to.eql(false);
52+
});
53+
it('should not speak if speechSynthesis is not supported', () => {
54+
global.window.speechSynthesis = undefined;
55+
const speak = speakFn({ enable: true });
56+
speak({});
57+
expect(speakSpy.called).to.eql(false);
58+
});
59+
it("should not speak if it's user msg", () => {
60+
const speak = speakFn({ enable: true });
61+
speak({ user: true });
62+
expect(speakSpy.called).to.eql(false);
63+
});
64+
it('should speak empty string (nothing)', () => {
65+
const speak = speakFn({ enable: true });
66+
speak({});
67+
expect(speakSpy.getCall(0).args[0]).to.eql({ text: '', lang: undefined, voice: undefined });
68+
});
69+
});
2870
});

0 commit comments

Comments
 (0)