-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnow.test.ts
32 lines (26 loc) · 985 Bytes
/
now.test.ts
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
import { beforeEach, describe, expect, it } from 'vitest';
import type { XFormsTestContext } from '../helpers.ts';
import { createXFormsTestContext } from '../helpers.ts';
describe('#now()', () => {
let testContext: XFormsTestContext;
beforeEach(() => {
testContext = createXFormsTestContext();
});
// ODK spec says:
// > Deviates from XForms 1.0 in that it returns the current date and time
// > including timezone offset (i.e. not normalized to UTC) as described
// > under the dateTime datatype.
it('should return a timestamp for this instant', () => {
// given
const now = new Date();
const today = `${now.getFullYear()}-${(1 + now.getMonth()).toString().padStart(2, '0')}-${now
.getDate()
.toString()
.padStart(2, '0')}`;
// when
const result = testContext.evaluate('now()', null, XPathResult.STRING_TYPE).stringValue;
expect(result.split('T')[0]).toEqual(today);
// assert timezone is included
expect(result).toMatch(/-07:00$/);
});
});