Unit Testing Serializers/Adapters?

After some vigorous Googling, I couldn’t find examples of testing serializers/adapters in qunit. Specifically, I’m looking for ways to test methods like “normalizeFindAllResponse”. Any thoughts?

Thank you!

3 Likes

What I typically do is test my serializers and adapters through the moduleForModel helper in conjunction with an http mock library. Using that test helper gives you implicit access to the store via this.store, with which you can drive the flow. You’d simply set up your payload as a javascript object with the format you want your serializer to parse, and you set up your expected http request (url, method, etc) in the way you want your adapter process. This allows you to test your calls more like your clients would call them.

Now I believe you can still unit test individual serializers and adapters. That would be a matter of using moduleFor(serializer:your-serializer’, {…});` and testing just as you would other unit tests.

2 Likes

how do you inject the store into your serializer test?

Edit: Nevermind, I figured it out and wrote a blog post on it: 404 Not Found

1 Like