Testing Ember
Data Transforms
Sara Raasch
My API is dumb
Or at least it’s treatments of dates is
Api /litter/:id (I SELL PUPPIES WHAT DO YOU EXPECT)
Response
{
"litter":{
"id":1,
"publishedAt":"2017-01-13 00:00:00",
"birthDate":"2015-05-01",
"deletedAt":null,
"createdAt":"2016-08-16 15:07:36",
"updatedAt":"2016-08-16 15:07:36",
...
}
}
Uhh those dates though?
2015-01-01
2016-08-16 15:07:36
I guess I’m just supposed to know
we mean utc? My browser sure
doesn’t
Not ISO8601 :(
Dates don’t serialize back like
that
app/transforms/day.js
Great, my days are
dates now
How do I test this? Seems kinda important to
my app?
tests/unit/transforms/day-test.js
Uhh, ok thanks for that helpful boilerplate
I’ll check the ember docs
http://emberjs.com/api/data/classes/DS.Transform.html#conten
t
Uhh tells me how to make one, what it needs, nothing on
testing
I’ll check David’s blog, he knows everything
http://thejsguy.com/2015/11/23/a-look-into-ember-data-transf
orms.html
Tons of helpful info here, but nothing on testing
Ok one last look at a transform addon I was looking at
https://github.com/pk4media/ember-cli-moment-transform
Ok, that’s really easy. I feel real dumb.
Basically only two things you need to know to test a
transform
transform.deserialize(SOMEDATA) transform.serialize(SOMEDATA)
All is now right with the world
Keep in touch!
Sara Raasch
sara@sararaasch.com
@sararaasch on the
twitters

Testing ember data transforms

  • 1.
  • 2.
    My API isdumb Or at least it’s treatments of dates is
  • 3.
    Api /litter/:id (ISELL PUPPIES WHAT DO YOU EXPECT) Response { "litter":{ "id":1, "publishedAt":"2017-01-13 00:00:00", "birthDate":"2015-05-01", "deletedAt":null, "createdAt":"2016-08-16 15:07:36", "updatedAt":"2016-08-16 15:07:36", ... } } Uhh those dates though? 2015-01-01 2016-08-16 15:07:36 I guess I’m just supposed to know we mean utc? My browser sure doesn’t Not ISO8601 :( Dates don’t serialize back like that
  • 4.
  • 5.
    Great, my daysare dates now How do I test this? Seems kinda important to my app?
  • 6.
  • 7.
    Uhh, ok thanksfor that helpful boilerplate I’ll check the ember docs http://emberjs.com/api/data/classes/DS.Transform.html#conten t Uhh tells me how to make one, what it needs, nothing on testing I’ll check David’s blog, he knows everything http://thejsguy.com/2015/11/23/a-look-into-ember-data-transf orms.html Tons of helpful info here, but nothing on testing
  • 8.
    Ok one lastlook at a transform addon I was looking at https://github.com/pk4media/ember-cli-moment-transform Ok, that’s really easy. I feel real dumb.
  • 9.
    Basically only twothings you need to know to test a transform transform.deserialize(SOMEDATA) transform.serialize(SOMEDATA)
  • 10.
    All is nowright with the world
  • 11.
    Keep in touch! SaraRaasch sara@sararaasch.com @sararaasch on the twitters