Skip to content

Instantly share code, notes, and snippets.

@bbshih
bbshih / momentMock.js
Last active February 22, 2023 18:27 — forked from lededje/gist:44aeddf1dc2a5e6064e3b29dc35a7a2d
Jest Mocking Moment to same time zone for tests
// To mock globally in all your tests, add to setupTestFrameworkScriptFile in config:
// https://facebook.github.io/jest/docs/en/configuration.html#setuptestframeworkscriptfile-string
jest.mock('moment', () => {
const moment = require.requireActual('moment-timezone');
moment.tz.setDefault('America/Los_Angeles'); // Whatever timezone you want
return moment;
});

Keybase proof

I hereby claim:

  • I am bbshih on github.
  • I am billyshih (https://keybase.io/billyshih) on keybase.
  • I have a public key whose fingerprint is 6863 969C 0096 38AA 4FF1 1E10 CEAB D8DB B627 4091

To claim this, I am signing this object:

@bbshih
bbshih / form.js
Last active December 19, 2015 00:39 — forked from ouranos/form.js
Additional JS to use Formtastic-Bootstrap with Client_Side_Validations
ClientSideValidations.formBuilders["FormtasticBootstrap::FormBuilder"] = {
add: function (element, settings, message) {
if (element.data('valid') !== false) {
element.data('valid', false);
var $parent = element.closest('.controls');
$parent.parent().addClass('error');
$('<span/>').addClass('help-inline').text(message).appendTo($parent);
} else {
element.parent().find('span.help-inline').text(message);
}