blessing-skin-server/resources/assets/tests/js/feedback.test.js
2018-09-08 10:11:44 +08:00

29 lines
766 B
JavaScript

import { sendFeedback } from '@/js/feedback';
test('send feedback', async () => {
window.fetch = jest.fn()
.mockResolvedValueOnce({ ok: false })
.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve({ errno: 1 })
})
.mockResolvedValue({
ok: true,
json: () => Promise.resolve({ errno: 0 })
});
await sendFeedback();
expect(document.cookie).toBe('');
expect(fetch.mock.calls[0]).toMatchSnapshot();
await sendFeedback();
expect(document.cookie).toBe('');
await sendFeedback();
expect(document.cookie).toStartWith('feedback_sent=');
window.fetch.mockClear();
await sendFeedback();
expect(window.fetch).not.toBeCalled();
});