0
votes

I have created helper file in ember for formatting date using moment.js library. Helper has some if else conditions. When I generated this helper using ember-cli command, a test file also created. But i couldnt write test case inside it. When i run the test, it shows error that wbFormatDate (my helper name) is not a function. Have anybody faced this issue before? Please let me know the best practive to create test cases for helper in ember-cli application

1

1 Answers

1
votes

Let's say you have your helper defined in yourAppDir/helpers/wb-format-date.js file. In your test file you should import your helper and perform tests using imported object. Take a look at this:

import { formatDate } from "myApp/helpers/format-date";

module("FormatDateHelper");

test("format-date helper", function(assert) {
  var date, result;
  date = new Date(Date.UTC(2014, 5, 7));
  result = formatDate(date, "YYYY-MM-DD");
  return assert.equal(result, "2014-06-07");
});