This repository has been archived by the owner on Apr 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from Jasmine to Mocha + Sinon + Chai-bdd-expect
See #73, #73 (comment) - Rename integration_spec to acceptance_spec. - Convert acceptance specs to mocha. - Use an alternate idAttribute in all examples. - Going forward, all features will be tested using Models and Collections. - Moved legacy unit tests to jasmine/ for later conversion.
- Loading branch information
Showing
23 changed files
with
16,278 additions
and
330 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{StickyStorageAdapter} = window.Backbone.storageAdapters | ||
|
||
describe 'StickyStorageAdapter', -> | ||
describe 'creation', -> | ||
it 'takes a name in its constructor', -> | ||
# This should actually test that the created storage (IndexedDB, WebSQL, etc) uses this name. | ||
# But we trust Sticky to do its job :) | ||
storage = new StickyStorageAdapter 'SuperSizedStorage' | ||
expect(storage.name).toBe 'SuperSizedStorage' | ||
|
||
it 'initializes', -> | ||
storage = new StickyStorageAdapter | ||
storage.initialize().done -> | ||
expect(storage.store instanceof StickyStore).toBe true | ||
|
||
describe 'methods', -> | ||
it 'sets and gets a record', -> | ||
storage = new StickyStorageAdapter | ||
storage.initialize().done -> | ||
storage.setItem('key', {foo: 'bar'}).done -> | ||
storage.getItem('key').done (item) -> | ||
expect(item).toEqual foo: 'bar' | ||
|
||
it 'deletes a record', -> | ||
storage = new StickyStorageAdapter | ||
storage.initialize().done -> | ||
storage.setItem('key', {foo: 'bar'}).done -> | ||
storage.removeItem('key').done -> | ||
storage.getItem('key').done (item) -> | ||
expect(item).toBeNull() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{backboneSync, localSync, dualSync, localStorage} = window | ||
{Collection, Model, collection, model} = {} | ||
|
||
describe 'Backbone.dualStorage', -> | ||
@timeout 10 | ||
|
||
beforeEach -> | ||
backboneSync.calls = [] | ||
localStorage.clear() | ||
class Model extends Backbone.Model | ||
idAttribute: '_id' | ||
urlRoot: 'eyes/' | ||
class Collection extends Backbone.Collection | ||
model: Model | ||
url: Model::urlRoot | ||
collection = new Collection | ||
_id: 123 | ||
vision: 'crystal' | ||
model = collection.models[0] | ||
|
||
describe 'using backbone models and retrieving from local storage', -> | ||
it "fetches a model offline after saving it online", (done) -> | ||
saved = $.Deferred() | ||
model.save {}, success: -> | ||
saved.resolve() | ||
saved.done -> | ||
fetched = $.Deferred() | ||
retrievedModel = new Model _id: 123 | ||
retrievedModel.fetch remote: false, success: -> | ||
fetched.resolve() | ||
fetched.done -> | ||
expect(retrievedModel.get('vision')).to.equal('crystal') | ||
done() | ||
|
||
describe 'using backbone collections and retrieving from local storage', -> | ||
it 'loads a collection after adding several models to it', (done) -> | ||
allSaved = for id in [1..3] | ||
saved = $.Deferred() | ||
newModel = new Model _id: id | ||
newModel.save {}, success: -> saved.resolve() | ||
saved | ||
$.when(allSaved).done -> | ||
fetched = $.Deferred() | ||
collection.fetch remote: false, success: -> fetched.resolve() | ||
fetched.done -> | ||
expect(collection.length).to.equal(3) | ||
expect(collection.map (model) -> model.id).to.eql [1,2,3] | ||
done() | ||
|
||
describe 'success and error callback parameters', -> | ||
it "passes back the response into the remote method's callback", -> | ||
fetched = $.Deferred() | ||
model.remote = true | ||
model.fetch success: (args...) -> fetched.resolve(args) | ||
fetched.done (callbackResponse) -> | ||
expect(callbackResponse[0]).to.equal model | ||
expect(callbackResponse[1]).to.eql model.attributes |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.