ShafiVayyattukavil
ShafiVayyattukavil

Reputation: 151

Test cases for Helper in ember-cli application

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

Upvotes: 0

Views: 146

Answers (1)

Kuba Niechciał
Kuba Niechciał

Reputation: 974

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");
});

Upvotes: 1

Related Questions