Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
Switch from Jasmine to Mocha + Sinon + Chai-bdd-expect
Browse files Browse the repository at this point in the history
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
nilbus committed Jun 1, 2014
1 parent 7723141 commit 452af11
Show file tree
Hide file tree
Showing 23 changed files with 16,278 additions and 330 deletions.
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.
30 changes: 30 additions & 0 deletions jasmine/stickystorage_spec.coffee
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()
58 changes: 58 additions & 0 deletions jasmine/stickystorage_spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions spec/acceptance_spec.coffee
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
140 changes: 140 additions & 0 deletions spec/acceptance_spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 452af11

Please sign in to comment.