How can we improve Breeze.js?

Mocking Data Calls

Allow for Breeze's data service calls to be able to be overridden with mock data calls, so data can be seen without needs to make actual ajax calls for designing and testing. Similar to amplify's model and using mockJSON with it.

35 votes
Vote
Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)
You have left! (?) (thinking…)
John Papa shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

1 comment

Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)
Submitting...
  • Ward Bell commented  ·   ·  Flag as inappropriate

    Great idea. We already have plugging the AJAX call on our backlog because we don't want a dependency on jQuery. We'll get it in there "soon" so stay tuned.

    Meanwhile, there is another faking option that is backed into Breeze and that I use all the time for my tests. I simply create new entities and attach them to the EntityManager as "existing entities". In test mode, I add the local cache fetch strategy which turns any query into a cache-only query. The structure remains async (you get a promise back), but it's actually executed synchronously against the cache and does not attempt a server trip.

    You add such a strategy with this clause (a bit of a mouthful):
    "query = query.using(entityModel.FetchStrategy.FromLocalCache)"

    Your calling code (e.g., ViewModel) doesn't know that you are making this switch.

    Now simulating Save is a little trickier ... as it would be if you're trying to mock that with amplify ... because the caller is expecting the entities to be different after the save returns successfully (e.g., new keys assigned, change-state is "unmodified" etc.). Amplify won't do that automatically either. It's actually pretty easy to fake with a little Breeze code if you need it.

    None of this diminishes the value of this suggestion; we'll get to it.

Feedback and Knowledge Base