-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresend_func.test.js
48 lines (36 loc) · 1.04 KB
/
resend_func.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* @jest-environment jsdom
*/
const $ = require('jquery');
global.$ = $;
const module = require('planttracer')
const resend_func = module.resend_func
global.Audio = function() {
this.play = jest.fn();
};
describe('resend_func', () => {
let mockVal, mockHtml;
beforeAll(() => {
global.API_BASE = 'https://planttracer.com';
global.planttracer_endpoint = 'test-endpoint';
});
beforeEach(() => {
mockVal = jest.fn();
mockHtml = jest.fn();
global.$ = jest.fn((selector) => {
if (selector === '#email') {
return { val: mockVal };
}
if (selector === '#message') {
return { html: mockHtml };
}
});
$.post = jest.fn();
});
test('displays error message when email is empty', () => {
mockVal.mockReturnValue('');
resend_func();
expect(mockHtml).toHaveBeenCalledWith("<b>Please provide an email address</b>");
expect($.post).not.toHaveBeenCalled();
});
});