Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4826

Unit testing a model that uses a transform, which uses a service (need to mock a service in a unit test)

$
0
0

@corrspt wrote:

Hi everyone,

I've added a transform to a model of mine to deal with numbers with decimals (the problem of comma vs dot vs other separator). I want the backend to always receive numbers with dots, so I've create a transform called "decimal-value" that does that. It checks the current user's decimal separator and replaces it with a dot.

export default DS.Transform.extend({
userSession: service(),
  serialize(deserialized) {
   //do stuff and check the user session
  }
})

I've changed my models to use this transform in some of the attributes,

heatTemperature: attr('decimal-value'),

But now the unit test for this particular model fails with:

Promise rejected before it converts to json: Attempting to register an unknown factory: `session:user-session`

I've added the required needs on the model unit test to include the transform:decimal-value

Should I mock the user-session service? How do I do that in a unit test? Should I be following some different strategy?

Thanks for any input.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4826

Trending Articles