ember-moment icon indicating copy to clipboard operation
ember-moment copied to clipboard

Freeze moment for testing

Open AndreJoaquim opened this issue 5 years ago • 1 comments

Hey! I've used this add-on for a long time and I has served my needs perfectly.

However, one thing that I'd like to see included in this add-on is a helper to freeze moment (i.e. override moment.now) in tests, namely acceptance tests. Below I show what the API could look like:

import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { setupMoment } from 'ember-moment/test-support';

module('Integration | Component | x-event/date', function(hooks) {
  setupRenderingTest(hooks);
  setupMoment(hooks, '2042-01-01');

  test('it renders', async function(assert) {
    // This component only displays today's date in the format "DD/MM/YYYY"
    await render(hbs`{{x-event/date}}`);

    assert.dom(this.element).hasText('01/01/2042');
  });
});

This would allow (more) deterministic tests, instead of relying of always getting today's date to see if the behaviour(s) is(are) correct.

What do you think about this feature? Thanks! 😄

AndreJoaquim avatar Mar 21 '19 17:03 AndreJoaquim

@AndreJoaquim I love it! Feel free to send a PR (or anyone for that matter) if you have the cycles!

jasonmit avatar Apr 18 '19 05:04 jasonmit