Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test("dateToLocal works as expected", () => {
tzmock.register("UTC");
expect(localTime(dateToLocal(0))).toEqual([ 1970, 1, 1, 0, 0, 0, 0 ]);
expect(localTime(dateToLocal(1539980438))).toEqual([ 2018, 10, 19, 20, 20, 38, 0 ]);
expect(localTime(dateToLocal(1541708438))).toEqual([ 2018, 11, 8, 20, 20, 38, 0 ]);
tzmock.register("Brazil/East");
expect(localTime(dateToLocal(0))).toEqual([ 1969, 12, 31, 21, 0, 0, 0 ]);
expect(localTime(dateToLocal(1539980438))).toEqual([ 2018, 10, 19, 17, 20, 38, 0 ]);
expect(localTime(dateToLocal(1541708438))).toEqual([ 2018, 11, 8, 18, 20, 38, 0 ]); // DST on
tzmock.register("US/Pacific");
expect(localTime(dateToLocal(0))).toEqual([ 1969, 12, 31, 16, 0, 0, 0 ]);
expect(localTime(dateToLocal(1539980438))).toEqual([ 2018, 10, 19, 13, 20, 38, 0 ]); // DST on
expect(localTime(dateToLocal(1541708438))).toEqual([ 2018, 11, 8, 12, 20, 38, 0 ]);
});
test("dateToLocal works as expected", () => {
tzmock.register("UTC");
expect(localTime(dateToLocal(0))).toEqual([ 1970, 1, 1, 0, 0, 0, 0 ]);
expect(localTime(dateToLocal(1539980438))).toEqual([ 2018, 10, 19, 20, 20, 38, 0 ]);
expect(localTime(dateToLocal(1541708438))).toEqual([ 2018, 11, 8, 20, 20, 38, 0 ]);
tzmock.register("Brazil/East");
expect(localTime(dateToLocal(0))).toEqual([ 1969, 12, 31, 21, 0, 0, 0 ]);
expect(localTime(dateToLocal(1539980438))).toEqual([ 2018, 10, 19, 17, 20, 38, 0 ]);
expect(localTime(dateToLocal(1541708438))).toEqual([ 2018, 11, 8, 18, 20, 38, 0 ]); // DST on
tzmock.register("US/Pacific");
expect(localTime(dateToLocal(0))).toEqual([ 1969, 12, 31, 16, 0, 0, 0 ]);
expect(localTime(dateToLocal(1539980438))).toEqual([ 2018, 10, 19, 13, 20, 38, 0 ]); // DST on
expect(localTime(dateToLocal(1541708438))).toEqual([ 2018, 11, 8, 12, 20, 38, 0 ]);
});
beforeEach(() => {
timezoneMock.register(timezone);
// Date object with mocked TZ
tzDate = new Date();
buildVm({ time: date.getTime() });
});
// Configure
configure({ adapter: new Adapter() })
// Mock Modules
jest.mock('./components/identicon', () => () => <div>[Identicon]</div>)
// Mock Globals
Date.now = jest.fn(() => 1516916214006)
global.localStorage = {
getItem() {},
setItem() {}
}
// Mock Time
timezoneMock.register('UTC')
test("dateToUtc works as expected", () => {
tzmock.register("UTC");
expect(localTime(dateToUTC(0))).toEqual([ 1970, 1, 1, 0, 0, 0, 0 ]);
expect(localTime(dateToUTC(1539980438))).toEqual([ 2018, 10, 19, 20, 20, 38, 0 ]);
expect(localTime(dateToUTC(1541708438))).toEqual([ 2018, 11, 8, 20, 20, 38, 0 ]);
tzmock.register("Brazil/East");
expect(localTime(dateToUTC(0))).toEqual([ 1970, 1, 1, 0, 0, 0, 0 ]);
expect(localTime(dateToUTC(1539980438))).toEqual([ 2018, 10, 19, 20, 20, 38, 0 ]);
expect(localTime(dateToUTC(1541708438))).toEqual([ 2018, 11, 8, 20, 20, 38, 0 ]);
tzmock.register("US/Pacific");
expect(localTime(dateToUTC(0))).toEqual([ 1970, 1, 1, 0, 0, 0, 0 ]);
expect(localTime(dateToUTC(1539980438))).toEqual([ 2018, 10, 19, 20, 20, 38, 0 ]);
expect(localTime(dateToUTC(1541708438))).toEqual([ 2018, 11, 8, 20, 20, 38, 0 ]);
function registerMock() {
timezone_mock.register('US/Pacific');
var date = new Date(Date.now());
var tzo = date.getTimezoneOffset();
assert.ok(tzo === 420 || tzo === 480);
}
afterEach(() => tzmock.unregister());
beforeAll(() => {
timezoneMock.register('US/Pacific');
});
afterAll(() => {
beforeAll(() => {
timezoneMock.register('US/Pacific')
})
beforeAll(() => {
timezoneMock.register('US/Pacific');
});