-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactiveUrl.test.tsx
42 lines (36 loc) · 1.16 KB
/
activeUrl.test.tsx
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
import {
Validator,
activeUrl
} from '../../../src';
import fetchMock from 'jest-fetch-mock';
describe('test activeUrl rule', () => {
beforeEach(() => {
Validator.extend('active_url', activeUrl);
fetchMock.mockResponse((req: Request) => {
if (req.url === 'https://example.com/success') {
return Promise.resolve({ status: 200 });
} else {
return Promise.resolve({ status: 404 });
}
})
});
it('should always validate inputs and not validate non-inputs', async () => {
const input = document.createElement('input');
input.value = 'https://example.com'
const canvas = document.createElement('canvas');
const validator_input = new Validator([
input
],
['active_url'],
'');
const validator_canvas = new Validator([
canvas
],
['active_url'],
'');
await validator_input.validate();
expect(validator_input.getErrors().length).toBe(1);
await validator_canvas.validate();
expect(validator_canvas.getErrors().length).toBe(0);
});
});